From: Jarkko Hietaniemi Date: Sat, 31 Jul 1999 22:44:56 +0000 (+0000) Subject: Integer overflow iteration. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=893fe2c21345ec73429b2371c33adad8d22fc7f2;p=p5sagit%2Fp5-mst-13.2.git Integer overflow iteration. p4raw-id: //depot/cfgperl@3843 --- diff --git a/t/op/oct.t b/t/op/oct.t index 32b081c..27ac5aa 100755 --- a/t/op/oct.t +++ b/t/op/oct.t @@ -1,6 +1,6 @@ #!./perl -print "1..35\n"; +print "1..36\n"; print +(oct('0b10101') == 0b10101) ? "ok" : "not ok", " 1\n"; print +(oct('0b10101') == 025) ? "ok" : "not ok", " 2\n"; @@ -48,3 +48,6 @@ print +(oct('037777777777') == 4294967295) ? "ok" : "not ok", " 34\n"; print +(oct('0xffffffff') == 4294967295) ? "ok" : "not ok", " 35\n"; + +print +(hex('0xffffffff') == 4294967295) ? + "ok" : "not ok", " 36\n"; diff --git a/toke.c b/toke.c index d5e8fb7..55aba05 100644 --- a/toke.c +++ b/toke.c @@ -6298,7 +6298,7 @@ Perl_scan_num(pTHX_ char *start) static char *maxima[5] = { "", "0b11111111111111111111111111111111", "", - "0b37777777777", + "037777777777", "0xffffffff" }; char *base, *Base, *max; @@ -6324,7 +6324,7 @@ Perl_scan_num(pTHX_ char *start) /* read the rest of the number */ for (;;) { /* x is used in the overflow test, - b is the digit we're adding on */ + b is the digit we're adding on. */ UV x, b; switch (*s) { @@ -6410,7 +6410,7 @@ Perl_scan_num(pTHX_ char *start) sv = NEWSV(92,0); if (overflowed) { dTHR; - if (ckWARN(WARN_UNSAFE) && (NV) n > 4294967295.0) + if (ckWARN(WARN_UNSAFE) && n > 4294967295.0) Perl_warner(aTHX_ WARN_UNSAFE, "%s number > %s non-portable", Base, max); diff --git a/util.c b/util.c index 9d35e21..918f37b 100644 --- a/util.c +++ b/util.c @@ -2828,7 +2828,11 @@ Perl_scan_bin(pTHX_ char *start, I32 len, I32 *retlen) } if (!overflowed) rnv = (NV) ruv; - if (rnv > 4294967295.0) { + if ( ( overflowed && rnv > 4294967295.0) +#if UV_SIZEOF > 4 + || (!overflowed && ruv > 0xffffffff ) +#endif + ) { dTHR; if (ckWARN(WARN_UNSAFE)) Perl_warner(aTHX_ WARN_UNSAFE, @@ -2864,7 +2868,7 @@ Perl_scan_oct(pTHX_ char *start, I32 len, I32 *retlen) } } if (!overflowed) { - register xuv = ruv << 3; + register UV xuv = ruv << 3; if ((xuv >> 3) != ruv) { dTHR; @@ -2889,7 +2893,11 @@ Perl_scan_oct(pTHX_ char *start, I32 len, I32 *retlen) } if (!overflowed) rnv = (NV) ruv; - if (rnv > 4294967295.0) { + if ( ( overflowed && rnv > 4294967295.0) +#if UV_SIZEOF > 4 + || (!overflowed && ruv > 0xffffffff ) +#endif + ) { dTHR; if (ckWARN(WARN_UNSAFE)) Perl_warner(aTHX_ WARN_UNSAFE, @@ -2953,7 +2961,11 @@ Perl_scan_hex(pTHX_ char *start, I32 len, I32 *retlen) } if (!overflowed) rnv = (NV) ruv; - if (rnv > 4294967295.0) { + if ( ( overflowed && rnv > 4294967295.0) +#if UV_SIZEOF > 4 + || (!overflowed && ruv > 0xffffffff ) +#endif + ) { dTHR; if (ckWARN(WARN_UNSAFE)) Perl_warner(aTHX_ WARN_UNSAFE,