mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Have number_to_string handle the case when number < -MAX_INT.
Published in <sxs662uf7l9.fsf@florida.arsdigita.de>.
This commit is contained in:
parent
081e4eb4f4
commit
fbf0306dd7
@ -1,3 +1,7 @@
|
||||
2002-04-14 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||
|
||||
* utils.c (number_to_string): Handle the case when n < -INT_MAX.
|
||||
|
||||
2002-04-14 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||
|
||||
* init.c (comind): Use a marginally faster implementation of
|
||||
|
15
src/utils.c
15
src/utils.c
@ -1347,6 +1347,12 @@ numdigit (long number)
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/* A half-assed implementation of INT_MAX on machines that don't
|
||||
bother to define one. */
|
||||
#ifndef INT_MAX
|
||||
# define INT_MAX ((int) ~((unsigned)1 << 8 * sizeof (int) - 1))
|
||||
#endif
|
||||
|
||||
#define ONE_DIGIT(figure) *p++ = n / (figure) + '0'
|
||||
#define ONE_DIGIT_ADVANCE(figure) (ONE_DIGIT (figure), n %= (figure))
|
||||
|
||||
@ -1406,6 +1412,15 @@ number_to_string (char *buffer, long number)
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
if (n < -INT_MAX)
|
||||
{
|
||||
/* We cannot print a '-' and assign -n to n because -n would
|
||||
overflow. Let sprintf deal with this border case. */
|
||||
sprintf (buffer, "%ld", n);
|
||||
p += strlen (buffer);
|
||||
return p;
|
||||
}
|
||||
|
||||
*p++ = '-';
|
||||
n = -n;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user