summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-12-28 19:55:56 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-12-28 19:55:56 +0000
commit24d49c17ff0f21aad54a06ae1065494e6e626556 (patch)
treea35d37a29b5dd3ed938a5943dad60389ef1f0c13
parent79c1c09ad7d8b945e744760f535fd8e00a030ec5 (diff)
downloadperl-24d49c17ff0f21aad54a06ae1065494e6e626556.tar.gz
range operator does magical string increment iff both operands
are non-numbers, from Tom Phoenix <rootbeer@redcat.com>; fixed the "foreach (RANGE)" case as well p4raw-id: //depot/perl@4730
-rw-r--r--pp_ctl.c10
-rwxr-xr-xt/op/range.t11
2 files changed, 18 insertions, 3 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index c028b4eca5..34e18b5f32 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 1698db4a55..e8aecf5fc9 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";