]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
vasnprintf: Correct errno value in case of out-of-memory.
authorBruno Haible <bruno@clisp.org>
Sat, 24 Apr 2010 15:23:39 +0000 (17:23 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 25 Apr 2010 14:05:50 +0000 (16:05 +0200)
gettext-runtime/intl/ChangeLog
gettext-runtime/intl/vasnprintf.c
gettext-runtime/libasprintf/ChangeLog
gettext-runtime/libasprintf/vasnprintf.c

index 985a7e5f2894e6abf0828ad5ba0e327fa7396d1a..cdf1bc3d681e58204365d1c909b170eaf6542698 100644 (file)
@@ -1,3 +1,10 @@
+2010-04-24  Bruno Haible  <bruno@clisp.org>
+
+       vasnprintf: Correct errno value in case of out-of-memory.
+       * vasnprintf.c (VASNPRINTF): Set errno to 0 before calling SNPRINTF or
+       sprintf. Use the errno value from SNPRINTF or sprintf.
+       Reported by Ian Beckwith <ianb@erislabs.net>.
+
 2010-04-10  Bruno Haible  <bruno@clisp.org>
 
        vasnprintf: Correct handling of unconvertible wide string arguments.
index b4331ea2dd194cf2ec877fa916c432dee4c78284..82d4b94c88106401489fc218a8c454e1cbf0585f 100644 (file)
@@ -4954,6 +4954,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       }
 #endif
 
+                    errno = 0;
                     switch (type)
                       {
                       case TYPE_SCHAR:
@@ -5148,15 +5149,21 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     /* Attempt to handle failure.  */
                     if (count < 0)
                       {
+                        /* SNPRINTF or sprintf failed.  Save and use the errno
+                           that it has set, if any.  */
+                        int saved_errno = errno;
+
                         if (!(result == resultbuf || result == NULL))
                           free (result);
                         if (buf_malloced != NULL)
                           free (buf_malloced);
                         CLEANUP ();
                         errno =
-                          (dp->conversion == 'c' || dp->conversion == 's'
-                           ? EILSEQ
-                           : EINVAL);
+                          (saved_errno != 0
+                           ? saved_errno
+                           : (dp->conversion == 'c' || dp->conversion == 's'
+                              ? EILSEQ
+                              : EINVAL));
                         return NULL;
                       }
 
index f7ea8602cb778f201a87ef98ecf7733c4d79cff0..56172691605d780d52a4f77b74581b65a9ba289d 100644 (file)
@@ -1,3 +1,10 @@
+2010-04-24  Bruno Haible  <bruno@clisp.org>
+
+       vasnprintf: Correct errno value in case of out-of-memory.
+       * vasnprintf.c (VASNPRINTF): Set errno to 0 before calling SNPRINTF or
+       sprintf. Use the errno value from SNPRINTF or sprintf.
+       Reported by Ian Beckwith <ianb@erislabs.net>.
+
 2010-04-10  Bruno Haible  <bruno@clisp.org>
 
        vasnprintf: Correct handling of unconvertible wide string arguments.
index b4331ea2dd194cf2ec877fa916c432dee4c78284..82d4b94c88106401489fc218a8c454e1cbf0585f 100644 (file)
@@ -4954,6 +4954,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       }
 #endif
 
+                    errno = 0;
                     switch (type)
                       {
                       case TYPE_SCHAR:
@@ -5148,15 +5149,21 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     /* Attempt to handle failure.  */
                     if (count < 0)
                       {
+                        /* SNPRINTF or sprintf failed.  Save and use the errno
+                           that it has set, if any.  */
+                        int saved_errno = errno;
+
                         if (!(result == resultbuf || result == NULL))
                           free (result);
                         if (buf_malloced != NULL)
                           free (buf_malloced);
                         CLEANUP ();
                         errno =
-                          (dp->conversion == 'c' || dp->conversion == 's'
-                           ? EILSEQ
-                           : EINVAL);
+                          (saved_errno != 0
+                           ? saved_errno
+                           : (dp->conversion == 'c' || dp->conversion == 's'
+                              ? EILSEQ
+                              : EINVAL));
                         return NULL;
                       }