[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
vasnprintf: fix 2007-11-03 fix
From: |
Bruno Haible |
Subject: |
vasnprintf: fix 2007-11-03 fix |
Date: |
Fri, 9 Nov 2007 12:51:39 +0100 |
User-agent: |
KMail/1.5.4 |
The vasnprintf fix from 2007-11-03 has the effect that when a reallocation
is needed, the snprintf() result will fit but the test _whether_ the snprintf()
result did fit fails, so that another round of reallocation is performed.
Inefficient...
2007-11-09 Bruno Haible <address@hidden>
* lib/vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf
buffer. Fixes an inefficiency introduced on 2007-11-03.
--- lib/vasnprintf.c.orig 2007-11-09 12:48:01.000000000 +0100
+++ lib/vasnprintf.c 2007-11-09 12:44:50.000000000 +0100
@@ -4294,13 +4294,19 @@
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));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- vasnprintf: fix 2007-11-03 fix,
Bruno Haible <=