From: SADAHIRO Tomoyuki Date: Wed, 9 Nov 2005 02:12:00 +0000 (+0900) Subject: Re: [perl #37616] Bug in &= (string) and/or m// X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1a787b952b2a283c0366c148171c3bc150e9489a;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #37616] Bug in &= (string) and/or m// Message-Id: <20051109021035.69D8.BQW10602@nifty.com> p4raw-id: //depot/perl@26136 --- diff --git a/doop.c b/doop.c index 8733816..c23093c 100644 --- a/doop.c +++ b/doop.c @@ -1174,7 +1174,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right) } else if (SvOK(sv) || SvTYPE(sv) > SVt_PVMG) { dc = SvPV_force_nomg_nolen(sv); - if (SvCUR(sv) < (STRLEN)len) { + if (SvLEN(sv) < (STRLEN)(len + 1)) { dc = SvGROW(sv, (STRLEN)(len + 1)); (void)memzero(dc + SvCUR(sv), len - SvCUR(sv) + 1); } @@ -1303,6 +1303,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right) case OP_BIT_AND: while (len--) *dc++ = *lc++ & *rc++; + *dc = '\0'; break; case OP_BIT_XOR: while (len--) diff --git a/t/op/bop.t b/t/op/bop.t index 8729167..6bc1067 100755 --- a/t/op/bop.t +++ b/t/op/bop.t @@ -15,7 +15,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 => 146; +plan tests => 148; # numerics ok ((0xdead & 0xbeef) == 0x9ead); @@ -329,3 +329,14 @@ SKIP: { skip "No malloc wrap checks" unless $Config::Config{usemallocwrap}; like( runperl(prog => 'eval q($#a>>=1); print 1'), "^1\n?" ); } + +# [perl #37616] Bug in &= (string) and/or m// +{ + $a = "aa"; + $a &= "a"; + ok($a =~ /a+$/, 'ASCII "a" is NUL-terminated'); + + $b = "bb\x{100}"; + $b &= "b"; + ok($b =~ /b+$/, 'Unicode "b" is NUL-terminated'); +}