Published in <sxs662uf7l9.fsf@florida.arsdigita.de>.
+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
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))
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;
}