From 01e8ce7e11ae94ffee674a9631103674c0fcb6ca Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 9 Nov 2007 12:52:05 +0100 Subject: [PATCH] Fix inefficiency introduced on 2007-11-03. --- ChangeLog | 5 +++++ lib/vasnprintf.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff7b1d044..727651c88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2007-11-09 Bruno Haible + * lib/vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf + buffer. Fixes an inefficiency introduced on 2007-11-03. + +2007-11-09 Bruno Haible + * m4/locale-tr.m4 (gt_LOCALE_TR_UTF8) [BeOS]: Make this test return none instead of tr_TR. Fixes a failure of test-c-strcasecmp.c. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index b7b58dfc5..ccc531b57 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -4294,13 +4294,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)); -- 2.11.0