vasnprintf: Don't set errno to 0.
authorBruno Haible <bruno@clisp.org>
Fri, 15 Oct 2010 00:01:51 +0000 (02:01 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 15 Oct 2010 00:01:51 +0000 (02:01 +0200)
* lib/vasnprintf.c (VASNPRINTF): Save and restore errno around the
block that sets it to 0.
Reported by Gianluigi Tiesi <sherpya@netfarm.it>.

ChangeLog
lib/vasnprintf.c

index dc3a8d4299b245387e36e3786d85f4e76fb31d24..4e36a0ff999c664d4f8a4da2110e2b3e81d99bfb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-10-14  Bruno Haible  <bruno@clisp.org>
+
+       vasnprintf: Don't set errno to 0.
+       * lib/vasnprintf.c (VASNPRINTF): Save and restore errno around the
+       block that sets it to 0.
+       Reported by Gianluigi Tiesi <sherpya@netfarm.it>.
+
 2010-10-14  Bruno Haible  <bruno@clisp.org>
 
        socketlib: Fix.
index 388ab0dbe31eb9f1941e713a02f3e085d99ebc3d..59ea01cc7e0cf3321c371fd6a0d8bbcace6c8ac9 100644 (file)
@@ -4599,6 +4599,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 TCHAR_T *fbp;
                 unsigned int prefix_count;
                 int prefixes[2] IF_LINT (= { 0 });
+                int orig_errno;
 #if !USE_SNPRINTF
                 size_t tmp_length;
                 TCHAR_T tmpbuf[700];
@@ -4902,6 +4903,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 *(TCHAR_T *) (result + length) = '\0';
 #endif
 
+                orig_errno = errno;
+
                 for (;;)
                   {
                     int count = -1;
@@ -5499,6 +5502,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     length += count;
                     break;
                   }
+                errno = orig_errno;
 #undef pad_ourselves
 #undef prec_ourselves
               }