changeset 37499:5fe05aea43d1

vasnprintf: fix potential incorrect errno 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.
author Pádraig Brady <P@draigBrady.com>
date Mon, 08 Dec 2014 09:46:38 +0000
parents c121cc9a1948
children 73eb9fd6855c
files lib/vasnprintf.c
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lib/vasnprintf.c	Sat Dec 06 01:14:02 2014 +0000
+++ b/lib/vasnprintf.c	Mon Dec 08 09:46:38 2014 +0000
@@ -5179,18 +5179,21 @@
                         /* 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;
                       }