Mercurial > hg > octave-nkf > gnulib-hg
changeset 9462:7bbddc0fae4a
Document and work around a BeOS snprintf() bug.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 09 Nov 2007 12:59:46 +0100 |
parents | c6d483077434 |
children | 1388aa25dd3d |
files | ChangeLog doc/functions/snprintf.texi doc/functions/vsnprintf.texi lib/vasnprintf.c |
diffstat | 4 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-11-09 Bruno Haible <bruno@clisp.org> + + * doc/functions/snprintf.texi: Mention BeOS deficiency. + * doc/functions/vsnprintf.texi: Likewise. + * lib/vasnprintf.c (VASNPRINTF): Ensure that we never call snprintf + with a size argument < 2. + 2007-11-09 Bruno Haible <bruno@clisp.org> * lib/vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf
--- a/doc/functions/snprintf.texi +++ b/doc/functions/snprintf.texi @@ -61,6 +61,10 @@ This function does not fully support the @samp{n} directive on some platforms: HP-UX 11, mingw. @item +This function overwrites memory when a size = 1 argument is passed on some +platforms: +BeOS. +@item This function overwrites memory even when a zero size argument is passed on some platforms: OSF/1 5.1.
--- a/doc/functions/vsnprintf.texi +++ b/doc/functions/vsnprintf.texi @@ -61,6 +61,10 @@ This function does not fully support the @samp{n} directive on some platforms: HP-UX 11, mingw. @item +This function overwrites memory when a size = 1 argument is passed on some +platforms: +BeOS. +@item This function overwrites memory even when a zero size argument is passed on some platforms: HP-UX 11, OSF/1 5.1.
--- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -4046,9 +4046,13 @@ sizeof (TCHAR_T) divides sizeof (DCHAR_T) and alignof (TCHAR_T) <= alignof (DCHAR_T). */ # define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T)) + /* Ensure that maxlen below will be >= 2. Needed on BeOS, + where an snprintf() with maxlen==1 acts like sprintf(). */ + ENSURE_ALLOCATION (xsum (length, + (2 + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR)); /* Prepare checking whether snprintf returns the count via %n. */ - ENSURE_ALLOCATION (xsum (length, 1)); *(TCHAR_T *) (result + length) = '\0'; #endif