From: Jim Meyering Date: Thu, 21 Nov 2002 08:47:44 +0000 (+0000) Subject: (quotearg_buffer_restyled): If mbrtowc returns X-Git-Tag: v4.5.4~198 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=449872c53a89ded7f22d6dd73e22639d73f3e38b;p=thirdparty%2Fcoreutils.git (quotearg_buffer_restyled): If mbrtowc returns `(size_t) -1' (at which point it would also set errno to EILSEQ), then restore errno to its previous value. Reported by Phillip Jones via Tim Waugh as https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=76334. --- diff --git a/lib/quotearg.c b/lib/quotearg.c index 9d43956598..5e7e011846 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -443,6 +443,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, do { wchar_t w; + /* Be careful not to let mbrtowc change errno. */ + int saved_errno = errno; size_t bytes = mbrtowc (&w, &arg[i + m], argsize - (i + m), &mbstate); if (bytes == 0) @@ -450,6 +452,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, else if (bytes == (size_t) -1) { printable = 0; + /* Restore previous errno value. */ + errno = saved_errno; break; } else if (bytes == (size_t) -2)