From 90d598708199f0506e390bb9866e4bdb592f858a Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 24 Oct 2002 01:15:37 +0000 Subject: * stdio-common/tst-fphex.c: New file. * stdio-common/Makefile (tests): Add tst-fphex. * sysdeps/generic/printf_fphex.c (__printf_fphex): Fix initialization of WNUMEND. Fix counting of decimal point in WIDTH. Print '0' pad chars always before the value digits. Reported by James Antill . --- sysdeps/generic/printf_fphex.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'sysdeps/generic/printf_fphex.c') diff --git a/sysdeps/generic/printf_fphex.c b/sysdeps/generic/printf_fphex.c index 7dfb116aee..5b18c5ebb0 100644 --- a/sysdeps/generic/printf_fphex.c +++ b/sysdeps/generic/printf_fphex.c @@ -338,8 +338,8 @@ __printf_fphex (FILE *fp, /* Look for trailing zeroes. */ if (! zero_mantissa) { - wnumend = wnumbuf + sizeof wnumbuf; - numend = numbuf + sizeof numbuf; + wnumend = &wnumbuf[sizeof wnumbuf / sizeof wnumbuf[0]]; + numend = &numbuf[sizeof numbuf / sizeof numbuf[0]]; while (wnumend[-1] == L'0') { --wnumend; @@ -433,17 +433,13 @@ __printf_fphex (FILE *fp, + ((expbuf + sizeof expbuf) - expstr)); /* Exponent. */ - /* Count the decimal point. */ + /* Count the decimal point. + A special case when the mantissa or the precision is zero and the `#' + is not given. In this case we must not print the decimal point. */ if (precision > 0 || info->alt) width -= wide ? 1 : strlen (decimal); - /* A special case when the mantissa or the precision is zero and the `#' - is not given. In this case we must not print the decimal point. */ - if (precision == 0 && !info->alt) - ++width; /* This nihilates the +1 for the decimal-point - character in the following equation. */ - - if (!info->left && width > 0) + if (!info->left && info->pad != '0' && width > 0) PADN (' ', width); if (negative) @@ -458,6 +454,10 @@ __printf_fphex (FILE *fp, outchar (info->spec + ('x' - 'a')); else outchar (info->spec == 'A' ? 'X' : 'x'); + + if (!info->left && info->pad == '0' && width > 0) + PADN ('0', width); + outchar (leading); if (precision > 0 || info->alt) @@ -474,9 +474,6 @@ __printf_fphex (FILE *fp, PADN ('0', tofill); } - if (info->left && info->pad == '0' && width > 0) - PADN ('0', width); - if ('P' - 'A' == 'p' - 'a') outchar (info->spec + ('p' - 'a')); else -- cgit 1.4.1