summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2016-09-18 20:17:08 -0700
committerFather Chrysostomos <sprout@cpan.org>2016-09-18 20:20:44 -0700
commitb43665fffa48dd179eba1b5616d4ca35b4def876 (patch)
tree5d86335e2fc83e2d8a5a0e4839ce68c90301a322
parent71c89c826804a03f81e980d5286fdb0444490d86 (diff)
downloadperl-b43665fffa48dd179eba1b5616d4ca35b4def876.tar.gz
[perl #129287] Make UTF8 & append null
The & and &. operators were not appending a null byte to the string in utf8 mode. (The internal function that they use is the same. I used &. in the test just because its intent is clearer.)
-rw-r--r--doop.c1
-rw-r--r--t/op/bop.t14
2 files changed, 14 insertions, 1 deletions
diff --git a/doop.c b/doop.c
index ad9172ac1e..234a425fc5 100644
--- a/doop.c
+++ b/doop.c
@@ -1093,6 +1093,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
if (sv == left || sv == right)
(void)sv_usepvn(sv, dcorig, needlen);
SvCUR_set(sv, dc - dcorig);
+ *SvEND(sv) = 0;
break;
case OP_BIT_XOR:
while (lulen && rulen) {
diff --git a/t/op/bop.t b/t/op/bop.t
index 2afb8d7c81..1f96e9b67a 100644
--- a/t/op/bop.t
+++ b/t/op/bop.t
@@ -19,7 +19,7 @@ BEGIN {
# If you find tests are failing, please try adding names to tests to track
# down where the failure is, and supply your new names as a patch.
# (Just-in-time test naming)
-plan tests => 192 + (10*13*2) + 5 + 29;
+plan tests => 192 + (10*13*2) + 5 + 30;
# numerics
ok ((0xdead & 0xbeef) == 0x9ead);
@@ -664,3 +664,15 @@ is $^A, "123", '~v0 clears vstring magic on retval';
is(-1 >> $w + 1, -1, "IV -1 right shift $w + 1 == -1");
}
}
+
+# [perl #129287] UTF8 & was not providing a trailing null byte.
+# This test is a bit convoluted, as we want to make sure that the string
+# allocated for &’s target contains memory initialised to something other
+# than a null byte. Uninitialised memory does not make for a reliable
+# test. So we do &. on a longer non-utf8 string first.
+for (["aaa","aaa"],[substr ("a\x{100}",0,1), "a"]) {
+ use feature "bitwise";
+ no warnings "experimental::bitwise", "pack";
+ $byte = substr unpack("P2", pack "P", $$_[0] &. $$_[1]), -1;
+}
+is $byte, "\0", "utf8 &. appends null byte";