mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Don't use sprintf for printing WGINT_MIN; simply divide n by 10 and defer
printing the last digit.
This commit is contained in:
parent
d8f368d062
commit
b6fa9ce7be
@ -1,3 +1,9 @@
|
|||||||
|
2006-02-03 Hrvoje Niksic <hniksic@xemacs.org>
|
||||||
|
|
||||||
|
* utils.c (number_to_string): Don't use sprintf for printing
|
||||||
|
WGINT_MIN; simply divide n by 10 and defer printing the last
|
||||||
|
digit.
|
||||||
|
|
||||||
2006-02-03 Mauro Tortonesi <mauro@ferrara.linux.it>
|
2006-02-03 Mauro Tortonesi <mauro@ferrara.linux.it>
|
||||||
|
|
||||||
* http.c: Fixed support for Content-Disposition header.
|
* http.c: Fixed support for Content-Disposition header.
|
||||||
|
35
src/utils.c
35
src/utils.c
@ -1409,10 +1409,10 @@ numdigit (wgint number)
|
|||||||
#define DIGITS_18(mask) PR (mask), n %= (mask), DIGITS_17 ((mask) / 10)
|
#define DIGITS_18(mask) PR (mask), n %= (mask), DIGITS_17 ((mask) / 10)
|
||||||
#define DIGITS_19(mask) PR (mask), n %= (mask), DIGITS_18 ((mask) / 10)
|
#define DIGITS_19(mask) PR (mask), n %= (mask), DIGITS_18 ((mask) / 10)
|
||||||
|
|
||||||
/* SPRINTF_WGINT is used by number_to_string to handle pathological
|
/* SPRINTF_WGINT to portably support machines with strange sizes of
|
||||||
cases and to portably support strange sizes of wgint. Ideally this
|
wgint. Ideally this would just cast wgint to intmax_t and use
|
||||||
would just use "%j" and intmax_t, but many systems don't support
|
"%j", but many systems don't support it, so it's used only where
|
||||||
it, so it's used only if nothing else works. */
|
nothing else is known to work. */
|
||||||
#if SIZEOF_LONG >= SIZEOF_WGINT
|
#if SIZEOF_LONG >= SIZEOF_WGINT
|
||||||
# define SPRINTF_WGINT(buf, n) sprintf (buf, "%ld", (long) (n))
|
# define SPRINTF_WGINT(buf, n) sprintf (buf, "%ld", (long) (n))
|
||||||
#elif SIZEOF_LONG_LONG >= SIZEOF_WGINT
|
#elif SIZEOF_LONG_LONG >= SIZEOF_WGINT
|
||||||
@ -1451,21 +1451,29 @@ number_to_string (char *buffer, wgint number)
|
|||||||
char *p = buffer;
|
char *p = buffer;
|
||||||
wgint n = number;
|
wgint n = number;
|
||||||
|
|
||||||
|
int last_digit_char = 0;
|
||||||
|
|
||||||
#if (SIZEOF_WGINT != 4) && (SIZEOF_WGINT != 8)
|
#if (SIZEOF_WGINT != 4) && (SIZEOF_WGINT != 8)
|
||||||
/* We are running in a strange or misconfigured environment. Let
|
/* We are running in a very strange or misconfigured environment.
|
||||||
sprintf cope with it. */
|
Let sprintf cope with it. */
|
||||||
SPRINTF_WGINT (buffer, n);
|
p += SPRINTF_WGINT (buffer, n);
|
||||||
p += strlen (buffer);
|
|
||||||
#else /* (SIZEOF_WGINT == 4) || (SIZEOF_WGINT == 8) */
|
#else /* (SIZEOF_WGINT == 4) || (SIZEOF_WGINT == 8) */
|
||||||
|
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
if (n < -WGINT_MAX)
|
if (n < -WGINT_MAX)
|
||||||
{
|
{
|
||||||
/* -n would overflow. Have sprintf deal with this. */
|
/* n = -n would overflow because -n would evaluate to a
|
||||||
SPRINTF_WGINT (buffer, n);
|
wgint value larger than WGINT_MAX. Need to make n
|
||||||
p += strlen (buffer);
|
smaller and handle the last digit separately. */
|
||||||
return p;
|
int last_digit = n % 10;
|
||||||
|
/* The sign of n%10 is implementation-defined. */
|
||||||
|
if (last_digit < 0)
|
||||||
|
last_digit_char = '0' - last_digit;
|
||||||
|
else
|
||||||
|
last_digit_char = '0' + last_digit;
|
||||||
|
/* After n is made smaller, -n will not overflow. */
|
||||||
|
n /= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
*p++ = '-';
|
*p++ = '-';
|
||||||
@ -1505,6 +1513,9 @@ number_to_string (char *buffer, wgint number)
|
|||||||
else DIGITS_19 (1000000000*(W)1000000000);
|
else DIGITS_19 (1000000000*(W)1000000000);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (last_digit_char)
|
||||||
|
*p++ = last_digit_char;
|
||||||
|
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
#endif /* (SIZEOF_WGINT == 4) || (SIZEOF_WGINT == 8) */
|
#endif /* (SIZEOF_WGINT == 4) || (SIZEOF_WGINT == 8) */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user