]> Savannah Git Hosting - gnulib.git/commitdiff
vasnprintf: fix potential incorrect errno
authorPádraig Brady <P@draigBrady.com>
Mon, 8 Dec 2014 09:46:38 +0000 (09:46 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 8 Dec 2014 09:49:23 +0000 (09:49 +0000)
An adjustment of the previous commit c5c4f53b.

* lib/vasnprintf.c (VASNPRINTF): free() generally doesn't set errno,
but it can potentially in certain edge cases.
Reported by Eric Blake.

lib/vasnprintf.c

index 223be0763a9ebc9e2d00f3aac23aad1f70aa6cda..a73fad60b4ec031c3cbcbb301f7ff3a88a6a935a 100644 (file)
@@ -5179,18 +5179,21 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                         /* SNPRINTF or sprintf failed.  Save and use the errno
                            that it has set, if any.  */
                         int saved_errno = errno;
+                        if (saved_errno == 0)
+                          {
+                            if (dp->conversion == 'c' || dp->conversion == 's')
+                              saved_errno = EILSEQ;
+                            else
+                              saved_errno = EINVAL;
+                          }
 
                         if (!(result == resultbuf || result == NULL))
                           free (result);
                         if (buf_malloced != NULL)
                           free (buf_malloced);
-                        errno =
-                          (saved_errno != 0
-                           ? saved_errno
-                           : (dp->conversion == 'c' || dp->conversion == 's'
-                              ? EILSEQ
-                              : EINVAL));
                         CLEANUP ();
+
+                        errno = saved_errno;
                         return NULL;
                       }