[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: *printf: support of the 0 flag with inf and NaN
From: |
Bruno Haible |
Subject: |
Re: *printf: support of the 0 flag with inf and NaN |
Date: |
Sat, 19 May 2007 02:38:11 +0200 |
User-agent: |
KMail/1.5.4 |
There was a bug in this patch from 2007-05-06: when padding was requested
and the snprintf result did not fit into the initially allocated buffer,
the function could return a truncated result instead of calling snprintf
once again with a larger buffer. This fixes it.
2007-05-18 Bruno Haible <address@hidden>
* lib/vasnprintf.c (VASNPRINTF) [NEED_PRINTF_FLAG_ZERO]: Fix logic bug
introduced on 2007-05-06.
*** lib/vasnprintf.c 18 May 2007 23:35:38 -0000 1.46
--- lib/vasnprintf.c 19 May 2007 00:34:24 -0000
***************
*** 2841,2846 ****
--- 2841,2863 ----
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)
***************
*** 2853,2866 ****
proportionally, to avoid looping eternally if
snprintf() reports a too small count. */
size_t n =
! xmax (xsum (length, width),
xtimes (allocated, 2));
length += count;
ENSURE_ALLOCATION (n);
length -= count;
! maxlen = allocated - length; /* >= width */
}
# endif
{
# if USE_SNPRINTF
--- 2870,2884 ----
proportionally, to avoid looping eternally if
snprintf() reports a too small count. */
size_t n =
! xmax (xsum (length + 1, width),
xtimes (allocated, 2));
length += count;
ENSURE_ALLOCATION (n);
length -= count;
! maxlen = allocated - length; /* > width */
}
+ /* Here width < maxlen. */
# endif
{
# if USE_SNPRINTF
***************
*** 2919,2938 ****
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
! }
#if USE_SNPRINTF
/* The snprintf() result did fit. */
--- 2937,2943 ----
abort ();
#endif
! /* Here still count < maxlen. */
#if USE_SNPRINTF
/* The snprintf() result did fit. */