This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #133882] Assertion failure
authorKarl Williamson <khw@cpan.org>
Thu, 7 Mar 2019 20:44:34 +0000 (13:44 -0700)
committerKarl Williamson <khw@cpan.org>
Thu, 7 Mar 2019 20:50:24 +0000 (13:50 -0700)
The asserts in this routine were doing there job.  It was called
inappropriately, with len set to 0, which means for it that it's
supposed to calculate the length by using strlen().  But, len being 0
here meant that the input was empty.  When run under valgrind, errors
would also show up.

This function was being called to see if the string had any characters
that varied depending on if it is UTF-8 or not.  Since we know that the
answer is no if the length is 0, we simply don't call this function
then.

t/re/subst.t
toke.c

index d857b7d..2ce0804 100644 (file)
@@ -11,7 +11,7 @@ BEGIN {
     require './loc_tools.pl';
 }
 
-plan(tests => 277);
+plan(tests => 278);
 
 $_ = 'david';
 $a = s/david/rules/r;
@@ -1179,3 +1179,7 @@ __EOF__
     fresh_perl_is('my $a = "ha"; $a =~ s!|0?h\x{300}(?{})!!gi', "", {},
                   "[perl #133899] s!|0?h\\x{300}(?{})!!gi panics");
 }
+
+{
+    fresh_perl_is("s//00000000000format            \0          '0000000\\x{800}/;eval", "", {}, "RT #133882");
+}
diff --git a/toke.c b/toke.c
index 0bf86ad..c46b9e8 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -2068,6 +2068,7 @@ S_newSV_maybe_utf8(pTHX_ const char *const start, STRLEN len)
     SV * const sv = newSVpvn_utf8(start, len,
                     ! IN_BYTES
                   &&  UTF
+                  &&  len != 0
                   &&  is_utf8_non_invariant_string((const U8*)start, len));
     return sv;
 }