summaryrefslogtreecommitdiffstats
path: root/lib/vasnprintf.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/vasnprintf.c172
1 files changed, 104 insertions, 68 deletions
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 802790e..de20445 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -1,5 +1,5 @@
/* vsprintf with automatic memory allocation.
- Copyright (C) 1999, 2002-2023 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002-2024 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
@@ -83,7 +83,7 @@
#include <stdio.h> /* snprintf(), sprintf() */
#include <stdlib.h> /* abort(), malloc(), realloc(), free() */
#include <string.h> /* memcpy(), strlen() */
-#include <wchar.h> /* mbstate_t, mbrtowc(), mbrlen(), wcrtomb() */
+#include <wchar.h> /* mbstate_t, mbrtowc(), mbrlen(), wcrtomb(), mbszero() */
#include <errno.h> /* errno */
#include <limits.h> /* CHAR_BIT, INT_WIDTH, LONG_WIDTH */
#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */
@@ -247,7 +247,7 @@ local_strnlen (const char *string, size_t maxlen)
# endif
#endif
-#if (((!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_DIRECTIVE_LS) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
+#if (((!USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_WPRINTF_DIRECTIVE_LC) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_DIRECTIVE_LS) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
# if HAVE_WCSLEN
# define local_wcslen wcslen
# else
@@ -294,7 +294,7 @@ local_wcsnlen (const wchar_t *s, size_t maxlen)
static size_t
wctomb_fallback (char *s, wchar_t wc)
{
- static char hex[16] = "0123456789ABCDEF";
+ static char const hex[16] = "0123456789ABCDEF";
s[0] = '\\';
if (sizeof (wchar_t) > 2 && wc > 0xffff)
@@ -927,6 +927,14 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
return roomptr;
}
+/* Avoid pointless GCC warning "argument 1 value '18446744073709551615' exceeds
+ maximum object size 9223372036854775807", triggered by the use of xsum as
+ argument of malloc. */
+# if __GNUC__ >= 7
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Walloc-size-larger-than="
+# endif
+
/* Convert a bignum a >= 0, multiplied with 10^extra_zeroes, to decimal
representation.
Destroys the contents of a.
@@ -983,6 +991,10 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes)
return c_ptr;
}
+# if __GNUC__ >= 7
+# pragma GCC diagnostic pop
+# endif
+
# if NEED_PRINTF_LONG_DOUBLE
/* Assuming x is finite and >= 0:
@@ -1177,8 +1189,6 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
void *z_memory;
char *digits;
- if (memory == NULL)
- return NULL;
/* x = 2^e * m, hence
y = round (2^e * 10^n * m) = round (2^(e+n) * 5^n * m)
= round (2^s * 5^n * m). */
@@ -1386,10 +1396,13 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
static char *
scale10_round_decimal_long_double (long double x, int n)
{
- int e IF_LINT(= 0);
+ int e;
mpn_t m;
void *memory = decode_long_double (x, &e, &m);
- return scale10_round_decimal_decoded (e, m, memory, n);
+ if (memory != NULL)
+ return scale10_round_decimal_decoded (e, m, memory, n);
+ else
+ return NULL;
}
# endif
@@ -1404,10 +1417,13 @@ scale10_round_decimal_long_double (long double x, int n)
static char *
scale10_round_decimal_double (double x, int n)
{
- int e IF_LINT(= 0);
+ int e;
mpn_t m;
void *memory = decode_double (x, &e, &m);
- return scale10_round_decimal_decoded (e, m, memory, n);
+ if (memory != NULL)
+ return scale10_round_decimal_decoded (e, m, memory, n);
+ else
+ return NULL;
}
# endif
@@ -2319,6 +2335,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
if (dp->conversion == 'n')
{
+#if NEED_PRINTF_WITH_N_DIRECTIVE
switch (a.arg[dp->arg_index].type)
{
case TYPE_COUNT_SCHAR_POINTER:
@@ -2363,6 +2380,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
default:
abort ();
}
+#else
+ abort ();
+#endif
}
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
@@ -2749,14 +2769,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
}
#endif
-#if WIDE_CHAR_VERSION && !DCHAR_IS_TCHAR
+#if WIDE_CHAR_VERSION && (!DCHAR_IS_TCHAR || NEED_WPRINTF_DIRECTIVE_LC)
else if ((dp->conversion == 's'
&& a.arg[dp->arg_index].type == TYPE_WIDE_STRING)
|| (dp->conversion == 'c'
&& a.arg[dp->arg_index].type == TYPE_WIDE_CHAR))
{
/* %ls or %lc in vasnwprintf. See the specification of
- fwprintf. */
+ fwprintf. */
/* It would be silly to use snprintf ("%ls", ...) and then
convert back the result from a char[] to a wchar_t[].
Instead, just copy the argument wchar_t[] to the result. */
@@ -2991,7 +3011,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
wide characters, from the left. */
# if HAVE_MBRTOWC
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
arg_end = arg;
characters = 0;
@@ -3019,7 +3039,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
characters. */
# if HAVE_MBRTOWC
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
arg_end = arg;
characters = 0;
@@ -3063,7 +3083,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
size_t remaining;
# if HAVE_MBRTOWC
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
ENSURE_ALLOCATION (xsum (length, characters));
for (remaining = characters; remaining > 0; remaining--)
@@ -3089,7 +3109,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
{
# if HAVE_MBRTOWC
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
while (arg < arg_end)
{
@@ -3141,7 +3161,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
at most PRECISION bytes, from the left. */
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
arg_end = arg;
characters = 0;
@@ -3174,7 +3194,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
bytes. */
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
arg_end = arg;
characters = 0;
@@ -3214,7 +3234,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
size_t remaining;
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
for (remaining = characters; remaining > 0; )
{
@@ -3283,7 +3303,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
size_t remaining;
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
ENSURE_ALLOCATION (xsum (length, characters));
for (remaining = characters; remaining > 0; )
@@ -3309,7 +3329,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
{
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
while (arg < arg_end)
{
@@ -3408,21 +3428,18 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
{
/* Count the number of bytes. */
characters = 0;
- if (arg != 0)
- {
- char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
- int count;
+ char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
+ int count;
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbstate_t state;
+ mbszero (&state);
# endif
- count = local_wcrtomb (cbuf, arg, &state);
- if (count < 0)
- /* Cannot convert. */
- goto fail_with_EILSEQ;
- characters = count;
- }
+ count = local_wcrtomb (cbuf, arg, &state);
+ if (count < 0)
+ /* Cannot convert. */
+ goto fail_with_EILSEQ;
+ characters = count;
}
# if DCHAR_IS_TCHAR
else
@@ -3434,13 +3451,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# if !DCHAR_IS_TCHAR
/* Convert the string into a piece of temporary memory. */
- if (characters > 0) /* implies arg != 0 */
+ if (characters > 0)
{
char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
int count;
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
count = local_wcrtomb (cbuf, arg, &state);
@@ -3491,12 +3508,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
{
/* We know the number of bytes in advance. */
ENSURE_ALLOCATION (xsum (length, characters));
- if (characters > 0) /* implies arg != 0 */
+ if (characters > 0)
{
int count;
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
# endif
count = local_wcrtomb (result + length, arg, &state);
@@ -3508,23 +3525,20 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
else
{
- if (arg != 0)
- {
- char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
- int count;
+ char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
+ int count;
# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbstate_t state;
+ mbszero (&state);
# endif
- count = local_wcrtomb (cbuf, arg, &state);
- if (count < 0)
- /* Cannot convert. */
- goto fail_with_EILSEQ;
- ENSURE_ALLOCATION (xsum (length, count));
- memcpy (result + length, cbuf, count);
- length += count;
- }
+ count = local_wcrtomb (cbuf, arg, &state);
+ if (count < 0)
+ /* Cannot convert. */
+ goto fail_with_EILSEQ;
+ ENSURE_ALLOCATION (xsum (length, count));
+ memcpy (result + length, cbuf, count);
+ length += count;
}
# else
ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
@@ -3588,7 +3602,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
mbstate_t state;
wchar_t wc;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
int count = mbrtowc (&wc, &arg, 1, &state);
if (count < 0)
/* Invalid or incomplete multibyte character. */
@@ -5606,24 +5620,24 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
{
arg_type type = a.arg[dp->arg_index].type;
int flags = dp->flags;
-#if (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#if (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
int has_width;
#endif
-#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
size_t width;
#endif
-#if !USE_SNPRINTF || (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR) || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#if !USE_SNPRINTF || (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR) || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
int has_precision;
size_t precision;
#endif
-#if NEED_PRINTF_UNBOUNDED_PRECISION
+#if NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
int prec_ourselves;
#else
# define prec_ourselves 0
#endif
#if (WIDE_CHAR_VERSION && MUSL_LIBC) || NEED_PRINTF_FLAG_LEFTADJUST
# define pad_ourselves 1
-#elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
int pad_ourselves;
#else
# define pad_ourselves 0
@@ -5638,10 +5652,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
TCHAR_T *tmp;
#endif
-#if (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#if (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
has_width = 0;
#endif
-#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#if !USE_SNPRINTF || WIDE_CHAR_VERSION || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
width = 0;
if (dp->width_start != dp->width_end)
{
@@ -5669,13 +5683,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
width = xsum (xtimes (width, 10), *digitp++ - '0');
while (digitp != dp->width_end);
}
-# if (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+# if (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
has_width = 1;
# endif
}
#endif
-#if !USE_SNPRINTF || (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR) || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#if !USE_SNPRINTF || (WIDE_CHAR_VERSION && DCHAR_IS_TCHAR) || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
has_precision = 0;
precision = 6;
if (dp->precision_start != dp->precision_end)
@@ -5708,9 +5722,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
#endif
/* Decide whether to handle the precision ourselves. */
-#if NEED_PRINTF_UNBOUNDED_PRECISION
+#if NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
switch (dp->conversion)
{
+# if NEED_PRINTF_UNBOUNDED_PRECISION
case 'd': case 'i': case 'u':
case 'b':
#if SUPPORT_GNU_PRINTF_DIRECTIVES \
@@ -5718,9 +5733,21 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
case 'B':
#endif
case 'o':
- case 'x': case 'X': case 'p':
prec_ourselves = has_precision && (precision > 0);
break;
+# endif
+ case 'x': case 'X': case 'p':
+ prec_ourselves =
+ has_precision
+ && (0
+# if NEED_PRINTF_FLAG_ALT_PRECISION_ZERO
+ || (precision == 0)
+# endif
+# if NEED_PRINTF_UNBOUNDED_PRECISION
+ || (precision > 0)
+# endif
+ );
+ break;
default:
prec_ourselves = 0;
break;
@@ -5728,7 +5755,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
#endif
/* Decide whether to perform the padding ourselves. */
-#if !((WIDE_CHAR_VERSION && MUSL_LIBC) || NEED_PRINTF_FLAG_LEFTADJUST) && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION)
+#if !((WIDE_CHAR_VERSION && MUSL_LIBC) || NEED_PRINTF_FLAG_LEFTADJUST) && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION)
switch (dp->conversion)
{
# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO
@@ -6492,7 +6519,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
#endif
-#if NEED_PRINTF_UNBOUNDED_PRECISION
+#if NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
if (prec_ourselves)
{
/* Handle the precision. */
@@ -6552,6 +6579,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
count += insert;
}
+# if NEED_PRINTF_FLAG_ALT_PRECISION_ZERO
+ else if (precision == 0
+ && move == 1
+ && prec_ptr[prefix_count] == '0')
+ {
+ /* Replace the "0" result with an empty string. */
+ count = prefix_count;
+ }
+# endif
}
#endif
@@ -6586,7 +6622,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
wide character array. */
mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
tmpdst_len = 0;
{
const TCHAR_T *src = tmpsrc;
@@ -6610,7 +6646,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
if (tmpdst == NULL)
goto out_of_memory;
- memset (&state, '\0', sizeof (mbstate_t));
+ mbszero (&state);
{
DCHAR_T *destptr = tmpdst;
const TCHAR_T *src = tmpsrc;
@@ -6706,7 +6742,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
/* Here count <= allocated - length. */
/* Perform padding. */
-#if (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+#if (WIDE_CHAR_VERSION && MUSL_LIBC) || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_FLAG_ALT_PRECISION_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
if (pad_ourselves && has_width)
{
size_t w;