From b5ff17ffd797dbcd5b4b815200936d729725c9d2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 9 Nov 2007 12:59:46 +0100 Subject: [PATCH] Document and work around a BeOS snprintf() bug. --- ChangeLog | 7 +++++++ doc/functions/snprintf.texi | 4 ++++ doc/functions/vsnprintf.texi | 4 ++++ lib/vasnprintf.c | 6 +++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 727651c886..09587c1c71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-11-09 Bruno Haible + + * 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 * lib/vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf diff --git a/doc/functions/snprintf.texi b/doc/functions/snprintf.texi index 7e5f2f8ac4..43ca802dba 100644 --- a/doc/functions/snprintf.texi +++ b/doc/functions/snprintf.texi @@ -61,6 +61,10 @@ HP-UX 11, IRIX 6.5, OSF/1 5.1, mingw. 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. diff --git a/doc/functions/vsnprintf.texi b/doc/functions/vsnprintf.texi index 13c009cf97..645ae70209 100644 --- a/doc/functions/vsnprintf.texi +++ b/doc/functions/vsnprintf.texi @@ -61,6 +61,10 @@ HP-UX 11, IRIX 6.5, OSF/1 5.1, mingw. 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. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index ccc531b57b..d6b012a4ac 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -4046,9 +4046,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, 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 -- 2.30.2