From 4fe3f0fa0e8a231fc577c0b8520dc57000b1e088 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Wed, 10 Mar 2004 22:45:48 +0100 Subject: [PATCH] range operator warnings / 64-bit fix Message-Id: <20040310214548.4f5e3ab1@r2d2> p4raw-id: //depot/perl@22532 --- pp_ctl.c | 19 +++++++++++-------- pp_hot.c | 4 ++-- t/op/range.t | 26 ++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/pp_ctl.c b/pp_ctl.c index ca0ad45..f0ac9fc 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -1067,9 +1067,9 @@ PP(pp_flop) if (GIMME == G_ARRAY) { dPOPPOPssrl; - register I32 i, j; + register IV i, j; register SV *sv; - I32 max; + IV max; if (SvGMAGICAL(left)) mg_get(left); @@ -1077,7 +1077,8 @@ PP(pp_flop) mg_get(right); if (RANGE_IS_NUMERIC(left,right)) { - if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX) + if ((SvOK(left) && SvNV(left) < IV_MIN) || + (SvOK(right) && SvNV(right) > IV_MAX)) DIE(aTHX_ "Range iterator outside integer range"); i = SvIV(left); max = SvIV(right); @@ -1790,17 +1791,19 @@ PP(pp_enteriter) cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs); if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) { dPOPss; - if (RANGE_IS_NUMERIC(sv,(SV*)cx->blk_loop.iterary)) { - if (SvNV(sv) < IV_MIN || - SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX) + SV *right = (SV*)cx->blk_loop.iterary; + if (RANGE_IS_NUMERIC(sv,right)) { + if ((SvOK(sv) && SvNV(sv) < IV_MIN) || + (SvOK(right) && SvNV(right) >= IV_MAX)) DIE(aTHX_ "Range iterator outside integer range"); cx->blk_loop.iterix = SvIV(sv); - cx->blk_loop.itermax = SvIV((SV*)cx->blk_loop.iterary); + cx->blk_loop.itermax = SvIV(right); } else { STRLEN n_a; cx->blk_loop.iterlval = newSVsv(sv); - SvPV_force(cx->blk_loop.iterlval,n_a); + (void) SvPV_force(cx->blk_loop.iterlval,n_a); + (void) SvPV(right,n_a); } } } diff --git a/pp_hot.c b/pp_hot.c index 011774c..f0ea572 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1837,8 +1837,8 @@ PP(pp_iter) if (cx->blk_loop.iterlval) { /* string increment */ register SV* cur = cx->blk_loop.iterlval; - STRLEN maxlen; - char *max = SvPV((SV*)av, maxlen); + STRLEN maxlen = 0; + char *max = SvOK((SV*)av) ? SvPV((SV*)av, maxlen) : ""; if (!SvNIOK(cur) && SvCUR(cur) <= maxlen) { if (SvREFCNT(*itersvp) == 1 && !SvMAGICAL(*itersvp)) { /* safe to reuse old SV */ diff --git a/t/op/range.t b/t/op/range.t index ce9bbf6..310f480 100755 --- a/t/op/range.t +++ b/t/op/range.t @@ -1,5 +1,12 @@ #!./perl +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Config; + print "1..37\n"; print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n"; @@ -47,12 +54,23 @@ print "not " unless join(",", @y) eq join(",", @x); print "ok 10\n"; # check bounds -@a = 0x7ffffffe..0x7fffffff; -print "not " unless "@a" eq "2147483646 2147483647"; +if ($Config{ivsize} == 8) { + @a = eval "0x7ffffffffffffffe..0x7fffffffffffffff"; + $a = "9223372036854775806 9223372036854775807"; + @b = eval "-0x7fffffffffffffff..-0x7ffffffffffffffe"; + $b = "-9223372036854775807 -9223372036854775806"; +} +else { + @a = eval "0x7ffffffe..0x7fffffff"; + $a = "2147483646 2147483647"; + @b = eval "-0x7fffffff..-0x7ffffffe"; + $b = "-2147483647 -2147483646"; +} + +print "not " unless "@a" eq $a; print "ok 11\n"; -@a = -0x7fffffff..-0x7ffffffe; -print "not " unless "@a" eq "-2147483647 -2147483646"; +print "not " unless "@b" eq $b; print "ok 12\n"; # check magic -- 2.7.4