Mercurial > gnulib
changeset 29130:113c190cc217
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 | f666d9b1fdbd |
children | 7500299cdad2 |
files | ChangeLog lib/vasnprintf.c |
diffstat | 2 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sat Nov 03 12:40:53 2007 +0100 +++ b/ChangeLog Sat Nov 03 15:22:52 2007 +0100 @@ -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 Sat Nov 03 12:40:53 2007 +0100 +++ b/lib/vasnprintf.c Sat Nov 03 15:22:52 2007 +0100 @@ -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.