summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2017-03-31 13:44:58 +0100
committerDavid Mitchell <davem@iabyn.com>2017-03-31 14:13:24 +0100
commit1b92e6949b737e92f61827f9c92afce9218e30ba (patch)
treedc6337456cd4e6bd0fe98c168602bcad4a2bedb1 /t
parent1190bf17f4131bb86c6cd460c77e9d02894ca2ec (diff)
downloadperl-1b92e6949b737e92f61827f9c92afce9218e30ba.tar.gz
vec(): defer lvalue out-of-range croaking
RT #131083 Recent commits v5.25.10-81-gd69c430 and v5.25.10-82-g67dd6f3 added out-of-range/overflow checks for the offset arg of vec(). However in lvalue context, these croaks now happen before the SVt_PVLV was created, rather than when its set magic was called. This means that something like sub f { $x = $_[0] } f(vec($s, -1, 8)) now croaks even though the out-of-range value never ended up getting used in lvalue context. This commit fixes things by, in pp_vec(), rather than croaking, just set flag bits in LvFLAGS() to indicate that the offset is -Ve / out-of-range. Then in Perl_magic_getvec(), return 0 if these flags are set, and in Perl_magic_setvec() croak with a suitable error.
Diffstat (limited to 't')
-rw-r--r--t/op/vec.t20
1 files changed, 19 insertions, 1 deletions
diff --git a/t/op/vec.t b/t/op/vec.t
index e50ffb7af8..5fa1879686 100644
--- a/t/op/vec.t
+++ b/t/op/vec.t
@@ -8,7 +8,7 @@ BEGIN {
use Config;
-plan(tests => 74);
+plan(tests => 78);
is(vec($foo,0,1), 0);
@@ -223,3 +223,21 @@ like($@, qr/^Modification of a read-only value attempted at /,
}
}
}
+
+# RT #131083 maybe-lvalue out of range should only croak if assigned to
+
+{
+ sub RT131083 { if ($_[0]) { $_[1] = 1; } $_[1]; }
+ my $s = "abc";
+ my $off = -1;
+ my $v = RT131083(0, vec($s, $off, 8));
+ is($v, 0, "RT131083 rval -1");
+ $v = eval { RT131083(1, vec($s, $off, 8)); };
+ like($@, qr/Negative offset to vec in lvalue context/, "RT131083 lval -1");
+
+ $off = ~0;
+ my $v = RT131083(0, vec($s, $off, 8));
+ is($v, 0, "RT131083 rval ~0");
+ $v = eval { RT131083(1, vec($s, $off, 8)); };
+ like($@, qr/Out of memory!/, "RT131083 lval ~0");
+}