Mercurial > hg > octave-lyh > gnulib-hg
changeset 9439:9d292d1d891c
Fix detection of overflow: don't assume that snprintf is C99 compliant.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 03 Nov 2007 15:22:52 +0100 |
parents | 290aa46b4526 |
children | 176074d93ed1 |
files | ChangeLog lib/vasnprintf.c |
diffstat | 2 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-11-03 Bruno Haible <bruno@clisp.org> + + * lib/vasnprintf.c (VASNPRINTF): Don't assume that snprintf's return + value is C99 compliant. + Needed for OSF/1 5.1. + 2007-11-03 Bruno Haible <bruno@clisp.org> Fix out-of-memory handling of vasnprintf.
--- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -3658,8 +3658,12 @@ } #if USE_SNPRINTF - /* Handle overflow of the allocated buffer. */ - if (count >= maxlen) + /* Handle overflow of the allocated buffer. + If such an overflow occurs, a C99 compliant snprintf() + returns a count >= maxlen. However, a non-compliant + snprintf() function returns only count = maxlen - 1. To + cover both cases, test whether count >= maxlen - 1. */ + if ((unsigned int) count + 1 >= maxlen) { /* If maxlen already has attained its allowed maximum, allocating more memory will not increase maxlen.