From: Bruno Haible Date: Sat, 24 Apr 2010 15:23:39 +0000 (+0200) Subject: vasnprintf: Correct errno value in case of out-of-memory. X-Git-Tag: v0.18~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=637bd298b73d7fe046067a7ed013e359494e7482;p=thirdparty%2Fgettext.git vasnprintf: Correct errno value in case of out-of-memory. --- diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index 985a7e5f2..cdf1bc3d6 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,10 @@ +2010-04-24 Bruno Haible + + 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 . + 2010-04-10 Bruno Haible vasnprintf: Correct handling of unconvertible wide string arguments. diff --git a/gettext-runtime/intl/vasnprintf.c b/gettext-runtime/intl/vasnprintf.c index b4331ea2d..82d4b94c8 100644 --- a/gettext-runtime/intl/vasnprintf.c +++ b/gettext-runtime/intl/vasnprintf.c @@ -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; } diff --git a/gettext-runtime/libasprintf/ChangeLog b/gettext-runtime/libasprintf/ChangeLog index f7ea8602c..561726916 100644 --- a/gettext-runtime/libasprintf/ChangeLog +++ b/gettext-runtime/libasprintf/ChangeLog @@ -1,3 +1,10 @@ +2010-04-24 Bruno Haible + + 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 . + 2010-04-10 Bruno Haible vasnprintf: Correct handling of unconvertible wide string arguments. diff --git a/gettext-runtime/libasprintf/vasnprintf.c b/gettext-runtime/libasprintf/vasnprintf.c index b4331ea2d..82d4b94c8 100644 --- a/gettext-runtime/libasprintf/vasnprintf.c +++ b/gettext-runtime/libasprintf/vasnprintf.c @@ -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; }