changeset 29152:83223e1a4900

Fix inefficiency introduced on 2007-11-03.
author Bruno Haible <bruno@clisp.org>
date Fri, 09 Nov 2007 12:52:05 +0100
parents 10dd3759b00d
children 15b4077884f2
files ChangeLog lib/vasnprintf.c
diffstat 2 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Nov 09 12:24:38 2007 +0100
+++ b/ChangeLog	Fri Nov 09 12:52:05 2007 +0100
@@ -1,3 +1,8 @@
+2007-11-09  Bruno Haible  <bruno@clisp.org>
+
+	* lib/vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf
+	buffer. Fixes an inefficiency introduced on 2007-11-03.
+
 2007-11-09  Bruno Haible  <bruno@clisp.org>
 
 	* m4/locale-tr.m4 (gt_LOCALE_TR_UTF8) [BeOS]: Make this test return
--- a/lib/vasnprintf.c	Fri Nov 09 12:24:38 2007 +0100
+++ b/lib/vasnprintf.c	Fri Nov 09 12:52:05 2007 +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));