]> sjero.net Git - wget/commitdiff
[svn] Have number_to_string handle the case when number < -MAX_INT.
authorhniksic <devnull@localhost>
Sun, 14 Apr 2002 19:18:33 +0000 (12:18 -0700)
committerhniksic <devnull@localhost>
Sun, 14 Apr 2002 19:18:33 +0000 (12:18 -0700)
Published in <sxs662uf7l9.fsf@florida.arsdigita.de>.

src/ChangeLog
src/utils.c

index 09d4bc700dd8556c22c5b79d0904f99ba1a52188..f54dd7f4c414e0323641ade8470f4eab8c40e65c 100644 (file)
@@ -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
index 335144932a1b8b894578a2100dcc86276671de83..a84237ee130eae8ac420a4f8d8e008fcd46c6bd1 100644 (file)
@@ -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;
     }