projects
/
pspp
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
48e570f
)
Fix logic bug introduced on 2007-05-06.
author
Bruno Haible
<bruno@clisp.org>
Sat, 19 May 2007 00:38:42 +0000
(
00:38
+0000)
committer
Bruno Haible
<bruno@clisp.org>
Sat, 19 May 2007 00:38:42 +0000
(
00:38
+0000)
ChangeLog
patch
|
blob
|
history
lib/vasnprintf.c
patch
|
blob
|
history
diff --git
a/ChangeLog
b/ChangeLog
index 8e4c10f1bc68363f0fd1241d7815b042d145bc46..a69b511010d28feabac6fe26300fce31a1777e7e 100644
(file)
--- a/
ChangeLog
+++ b/
ChangeLog
@@
-1,3
+1,8
@@
+2007-05-18 Bruno Haible <bruno@clisp.org>
+
+ * lib/vasnprintf.c (VASNPRINTF) [NEED_PRINTF_FLAG_ZERO]: Fix logic bug
+ introduced on 2007-05-06.
+
2007-05-18 Bruno Haible <bruno@clisp.org>
* tests/test-vasnprintf-posix.c (test_function): Also test the %e and
2007-05-18 Bruno Haible <bruno@clisp.org>
* tests/test-vasnprintf-posix.c (test_function): Also test the %e and
diff --git
a/lib/vasnprintf.c
b/lib/vasnprintf.c
index f67211b95f5fa2abd8524a4d44b78d755816f2cc..0a89f25d31e672759cea96fa01fa9a28bfc90361 100644
(file)
--- a/
lib/vasnprintf.c
+++ b/
lib/vasnprintf.c
@@
-2841,6
+2841,23
@@
VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
return NULL;
}
return NULL;
}
+ /* Make room for the result. */
+ if (count >= maxlen)
+ {
+ /* Need at least count bytes. But allocate
+ proportionally, to avoid looping eternally if
+ snprintf() reports a too small count. */
+ size_t n =
+ xmax (xsum (length, count), xtimes (allocated, 2));
+
+ ENSURE_ALLOCATION (n);
+#if USE_SNPRINTF
+ continue;
+#else
+ maxlen = allocated - length;
+#endif
+ }
+
/* Perform padding. */
#if NEED_PRINTF_FLAG_ZERO
if (pad_ourselves && has_width && count < width)
/* Perform padding. */
#if NEED_PRINTF_FLAG_ZERO
if (pad_ourselves && has_width && count < width)
@@
-2853,14
+2870,15
@@
VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
proportionally, to avoid looping eternally if
snprintf() reports a too small count. */
size_t n =
proportionally, to avoid looping eternally if
snprintf() reports a too small count. */
size_t n =
- xmax (xsum (length, width),
+ xmax (xsum (length
+ 1
, width),
xtimes (allocated, 2));
length += count;
ENSURE_ALLOCATION (n);
length -= count;
xtimes (allocated, 2));
length += count;
ENSURE_ALLOCATION (n);
length -= count;
- maxlen = allocated - length; /* >
=
width */
+ maxlen = allocated - length; /* > width */
}
}
+ /* Here width < maxlen. */
# endif
{
# if USE_SNPRINTF
# endif
{
# if USE_SNPRINTF
@@
-2919,20
+2937,7
@@
VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar
abort ();
#endif
abort ();
#endif
- /* Make room for the result. */
- if (count >= maxlen)
- {
- /* Need at least count bytes. But allocate
- proportionally, to avoid looping eternally if
- snprintf() reports a too small count. */
- size_t n =
- xmax (xsum (length, count), xtimes (allocated, 2));
-
- ENSURE_ALLOCATION (n);
-#if USE_SNPRINTF
- continue;
-#endif
- }
+ /* Here still count < maxlen. */
#if USE_SNPRINTF
/* The snprintf() result did fit. */
#if USE_SNPRINTF
/* The snprintf() result did fit. */