summaryrefslogtreecommitdiff
path: root/gl/vasnprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/vasnprintf.c')
-rw-r--r--gl/vasnprintf.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c
index 1ca8d534a0..e618901ba2 100644
--- a/gl/vasnprintf.c
+++ b/gl/vasnprintf.c
@@ -2889,8 +2889,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
length += n;
}
}
- }
# endif
+ }
#endif
#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
else if ((dp->conversion == 'a' || dp->conversion == 'A')
@@ -4953,6 +4953,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
#endif
+ errno = 0;
switch (type)
{
case TYPE_SCHAR:
@@ -5147,15 +5148,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;
}
@@ -5491,6 +5498,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
length += count;
break;
}
+#undef pad_ourselves
+#undef prec_ourselves
}
}
}