From: Bruno Haible Date: Fri, 9 Nov 2007 12:09:18 +0000 (+0000) Subject: Update from gnulib. X-Git-Tag: v0.18~506 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ff791ffb55574efc98500d7192511f7f127706b;p=thirdparty%2Fgettext.git Update from gnulib. --- diff --git a/gettext-runtime/intl/ChangeLog b/gettext-runtime/intl/ChangeLog index 7c3f75a3f..8f18d00e8 100644 --- a/gettext-runtime/intl/ChangeLog +++ b/gettext-runtime/intl/ChangeLog @@ -1,3 +1,13 @@ +2007-11-09 Bruno Haible + + * vasnprintf.c (VASNPRINTF): Ensure that we never call snprintf with a + size argument < 2. + +2007-11-09 Bruno Haible + + * vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf buffer. + Fixes an inefficiency introduced on 2007-11-03. + 2007-11-07 Bruno Haible * gettext-0.17 released. diff --git a/gettext-runtime/intl/vasnprintf.c b/gettext-runtime/intl/vasnprintf.c index 4a8e7f05a..a5fddfade 100644 --- a/gettext-runtime/intl/vasnprintf.c +++ b/gettext-runtime/intl/vasnprintf.c @@ -4047,9 +4047,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 @@ -4295,13 +4299,19 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, goto overflow; else { - /* Need at least count * sizeof (TCHAR_T) bytes. - But allocate proportionally, to avoid looping + /* Need at least (count + 1) * sizeof (TCHAR_T) + bytes. (The +1 is for the trailing NUL.) + But ask for (count + 2) * sizeof (TCHAR_T) + bytes, so that in the next round, we likely get + maxlen > (unsigned int) count + 1 + and so we don't get here again. + And allocate proportionally, to avoid looping eternally if snprintf() reports a too small count. */ size_t n = xmax (xsum (length, - (count + TCHARS_PER_DCHAR - 1) + ((unsigned int) count + 2 + + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR), xtimes (allocated, 2)); diff --git a/gettext-runtime/libasprintf/ChangeLog b/gettext-runtime/libasprintf/ChangeLog index e154abcae..afb4758ea 100644 --- a/gettext-runtime/libasprintf/ChangeLog +++ b/gettext-runtime/libasprintf/ChangeLog @@ -1,3 +1,13 @@ +2007-11-09 Bruno Haible + + * vasnprintf.c (VASNPRINTF): Ensure that we never call snprintf with a + size argument < 2. + +2007-11-09 Bruno Haible + + * vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf buffer. + Fixes an inefficiency introduced on 2007-11-03. + 2007-11-07 Bruno Haible * gettext-0.17 released. diff --git a/gettext-runtime/libasprintf/vasnprintf.c b/gettext-runtime/libasprintf/vasnprintf.c index 4a8e7f05a..a5fddfade 100644 --- a/gettext-runtime/libasprintf/vasnprintf.c +++ b/gettext-runtime/libasprintf/vasnprintf.c @@ -4047,9 +4047,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 @@ -4295,13 +4299,19 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, goto overflow; else { - /* Need at least count * sizeof (TCHAR_T) bytes. - But allocate proportionally, to avoid looping + /* Need at least (count + 1) * sizeof (TCHAR_T) + bytes. (The +1 is for the trailing NUL.) + But ask for (count + 2) * sizeof (TCHAR_T) + bytes, so that in the next round, we likely get + maxlen > (unsigned int) count + 1 + and so we don't get here again. + And allocate proportionally, to avoid looping eternally if snprintf() reports a too small count. */ size_t n = xmax (xsum (length, - (count + TCHARS_PER_DCHAR - 1) + ((unsigned int) count + 2 + + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR), xtimes (allocated, 2));