summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>1999-07-31 22:44:56 +0000
committerJarkko Hietaniemi <jhi@iki.fi>1999-07-31 22:44:56 +0000
commit893fe2c21345ec73429b2371c33adad8d22fc7f2 (patch)
tree40616f23c0e5583acd35f985de295e3ebf64efdb
parentd6a287148f674729887096e6af50b42b464c3451 (diff)
downloadperl-893fe2c21345ec73429b2371c33adad8d22fc7f2.tar.gz
Integer overflow iteration.
p4raw-id: //depot/cfgperl@3843
-rwxr-xr-xt/op/oct.t5
-rw-r--r--toke.c6
-rw-r--r--util.c20
3 files changed, 23 insertions, 8 deletions
diff --git a/t/op/oct.t b/t/op/oct.t
index 32b081c9a3..27ac5aa042 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 d5e8fb7a8e..55aba052c8 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 9d35e21c93..918f37b309 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,