Mercurial > hg > octave-jordi > gnulib-hg
diff lib/vasnprintf.c @ 13259:5aa26fc2aec0
vasnprintf: Correct errno value in case of out-of-memory.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 24 Apr 2010 17:18:48 +0200 (2010-04-24) |
parents | af2bd6fe2a98 |
children | cbb76cf0c6f1 |
line wrap: on
line diff
--- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -4953,6 +4953,7 @@ } #endif + errno = 0; switch (type) { case TYPE_SCHAR: @@ -5147,15 +5148,21 @@ /* 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; }