gawk/gawk-3.1.5-num2str.patch
2005-12-22 18:48:39 +00:00

38 lines
1.1 KiB
Diff

--- gawk-3.1.5/node.c.num2str 2005-07-26 20:07:43.000000000 +0200
+++ gawk-3.1.5/node.c 2005-12-22 19:41:55.000000000 +0100
@@ -151,6 +151,7 @@
register char *sp = buf;
double val;
char *orig, *trans, save;
+ register long num;
if (! do_traditional && (s->flags & INTLSTR) != 0) {
save = s->stptr[s->stlen];
@@ -163,9 +164,12 @@
return tmp_string(trans, strlen(trans));
}
- /* not an integral value, or out of range */
- if ((val = double_to_int(s->numbr)) != s->numbr
- || val < LONG_MIN || val > LONG_MAX) {
+ /* conversion to long overflows, or out of range, or not integral */
+ val = double_to_int(s->numbr);
+ num = (long) val;
+ if ( (s->numbr > 0 && num < 0)
+ || (s->numbr < 0 && num > 0)
+ || val < LONG_MIN || val > LONG_MAX || val != s->numbr) {
/*
* Once upon a time, if GFMT_WORKAROUND wasn't defined,
* we just blindly did this:
@@ -199,9 +203,7 @@
goto no_malloc;
} else {
- /* integral value */
- /* force conversion to long only once */
- register long num = (long) val;
+ /* integral value, in range, too! */
if (num < NVAL && num >= 0) {
sp = (char *) values[num];
s->stlen = 1;