From: Gurusamy Sarathy Date: Tue, 28 Dec 1999 19:55:56 +0000 (+0000) Subject: range operator does magical string increment iff both operands X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=39eb404022bff33467711717d8de9566914a79f1;p=p5sagit%2Fp5-mst-13.2.git range operator does magical string increment iff both operands are non-numbers, from Tom Phoenix ; fixed the "foreach (RANGE)" case as well p4raw-id: //depot/perl@4730 --- diff --git a/pp_ctl.c b/pp_ctl.c index c028b4e..34e18b5 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -997,7 +997,9 @@ PP(pp_flop) mg_get(right); if (SvNIOKp(left) || !SvPOKp(left) || - (looks_like_number(left) && *SvPVX(left) != '0') ) + SvNIOKp(right) || !SvPOKp(right) || + (looks_like_number(left) && *SvPVX(left) != '0' && + looks_like_number(right) && *SvPVX(right) != '0')) { if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX) DIE(aTHX_ "Range iterator outside integer range"); @@ -1674,7 +1676,11 @@ PP(pp_enteriter) if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) { dPOPss; if (SvNIOKp(sv) || !SvPOKp(sv) || - (looks_like_number(sv) && *SvPVX(sv) != '0')) { + SvNIOKp(cx->blk_loop.iterary) || !SvPOKp(cx->blk_loop.iterary) || + (looks_like_number(sv) && *SvPVX(sv) != '0' && + looks_like_number((SV*)cx->blk_loop.iterary) && + *SvPVX(cx->blk_loop.iterary) != '0')) + { if (SvNV(sv) < IV_MIN || SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX) DIE(aTHX_ "Range iterator outside integer range"); diff --git a/t/op/range.t b/t/op/range.t index 1698db4..e8aecf5 100755 --- a/t/op/range.t +++ b/t/op/range.t @@ -1,6 +1,6 @@ #!./perl -print "1..13\n"; +print "1..15\n"; print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n"; @@ -64,3 +64,12 @@ print "ok 12\n"; $bad = 1 unless $x eq 'a:b:c:d:e'; print $bad ? "not ok 13\n" : "ok 13\n"; } + +# Should use magical autoinc only when both are strings +print "not " unless 0 == (() = "0"..-1); +print "ok 14\n"; + +for my $x ("0"..-1) { + print "not "; +} +print "ok 15\n";