b8876f
From b43665fffa48dd179eba1b5616d4ca35b4def876 Mon Sep 17 00:00:00 2001
b8876f
From: Father Chrysostomos <sprout@cpan.org>
b8876f
Date: Sun, 18 Sep 2016 20:17:08 -0700
b8876f
Subject: [PATCH] [perl #129287] Make UTF8 & append null
b8876f
MIME-Version: 1.0
b8876f
Content-Type: text/plain; charset=UTF-8
b8876f
Content-Transfer-Encoding: 8bit
b8876f
b8876f
The & and &. operators were not appending a null byte to the string
b8876f
in utf8 mode.
b8876f
b8876f
(The internal function that they use is the same.  I used &. in the
b8876f
test just because its intent is clearer.)
b8876f
b8876f
Signed-off-by: Petr Písař <ppisar@redhat.com>
b8876f
---
b8876f
 doop.c     |  1 +
b8876f
 t/op/bop.t | 14 +++++++++++++-
b8876f
 2 files changed, 14 insertions(+), 1 deletion(-)
b8876f
b8876f
diff --git a/doop.c b/doop.c
b8876f
index ad9172a..234a425 100644
b8876f
--- a/doop.c
b8876f
+++ b/doop.c
b8876f
@@ -1093,6 +1093,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
b8876f
 	    if (sv == left || sv == right)
b8876f
 		(void)sv_usepvn(sv, dcorig, needlen);
b8876f
 	    SvCUR_set(sv, dc - dcorig);
b8876f
+	    *SvEND(sv) = 0;
b8876f
 	    break;
b8876f
 	case OP_BIT_XOR:
b8876f
 	    while (lulen && rulen) {
b8876f
diff --git a/t/op/bop.t b/t/op/bop.t
b8876f
index 2afb8d7..1f96e9b 100644
b8876f
--- a/t/op/bop.t
b8876f
+++ b/t/op/bop.t
b8876f
@@ -19,7 +19,7 @@ BEGIN {
b8876f
 # If you find tests are failing, please try adding names to tests to track
b8876f
 # down where the failure is, and supply your new names as a patch.
b8876f
 # (Just-in-time test naming)
b8876f
-plan tests => 192 + (10*13*2) + 5 + 29;
b8876f
+plan tests => 192 + (10*13*2) + 5 + 30;
b8876f
 
b8876f
 # numerics
b8876f
 ok ((0xdead & 0xbeef) == 0x9ead);
b8876f
@@ -664,3 +664,15 @@ is $^A, "123", '~v0 clears vstring magic on retval';
b8876f
         is(-1 >> $w + 1, -1, "IV -1 right shift $w + 1 == -1");
b8876f
     }
b8876f
 }
b8876f
+
b8876f
+# [perl #129287] UTF8 & was not providing a trailing null byte.
b8876f
+# This test is a bit convoluted, as we want to make sure that the string
b8876f
+# allocated for &’s target contains memory initialised to something other
b8876f
+# than a null byte.  Uninitialised memory does not make for a reliable
b8876f
+# test.  So we do &. on a longer non-utf8 string first.
b8876f
+for (["aaa","aaa"],[substr ("a\x{100}",0,1), "a"]) {
b8876f
+    use feature "bitwise";
b8876f
+    no warnings "experimental::bitwise", "pack";
b8876f
+    $byte = substr unpack("P2", pack "P", $$_[0] &. $$_[1]), -1;
b8876f
+}
b8876f
+is $byte, "\0", "utf8 &. appends null byte";
b8876f
-- 
b8876f
2.7.4
b8876f