From: Adam Krolnik Date: Sat, 12 Dec 1998 15:30:18 +0000 (-0600) Subject: applied suggested patch; added tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c1ab3db27b18a2a38753176364fd557b05bb547f;p=p5sagit%2Fp5-mst-13.2.git applied suggested patch; added tests Message-Id: <9812122130.AA03717@gypsy.eng.cyrix.com> Subject: Range operation doesn't handle IV_MAX p4raw-id: //depot/perl@2855 --- diff --git a/pp_ctl.c b/pp_ctl.c index e0b65e3..405c344 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -1065,22 +1065,25 @@ PP(pp_flop) if (GIMME == G_ARRAY) { dPOPPOPssrl; - register I32 i; + register I32 i, j; register SV *sv; I32 max; if (SvNIOKp(left) || !SvPOKp(left) || (looks_like_number(left) && *SvPVX(left) != '0') ) { - if (SvNV(left) < IV_MIN || SvNV(right) >= IV_MAX) + if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX) croak("Range iterator outside integer range"); i = SvIV(left); max = SvIV(right); if (max >= i) { - EXTEND_MORTAL(max - i + 1); - EXTEND(SP, max - i + 1); + j = max - i + 1; + EXTEND_MORTAL(j); + EXTEND(SP, j); } - while (i <= max) { + else + j = 0; + while (j--) { sv = sv_2mortal(newSViv(i++)); PUSHs(sv); } diff --git a/t/op/range.t b/t/op/range.t index 7999b86..01f5f70 100755 --- a/t/op/range.t +++ b/t/op/range.t @@ -1,6 +1,6 @@ #!./perl -print "1..10\n"; +print "1..12\n"; print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n"; @@ -46,3 +46,12 @@ foreach ('09'..'08') { print "not " unless join(",", @y) eq join(",", @x); print "ok 10\n"; +# check bounds +@a = 0x7ffffffe..0x7fffffff; +print "not " unless "@a" eq "2147483646 2147483647"; +print "ok 11\n"; + +@a = -0x7fffffff..-0x7ffffffe; +print "not " unless "@a" eq "-2147483647 -2147483646"; +print "ok 12\n"; +