develooper Front page | perl.perl5.porters | Postings from June 2006

[PATCH]: fix: [perl #39583] Pattern Match fails for specific length string

Thread Next
From:
demerphq
Date:
June 23, 2006 02:54
Subject:
[PATCH]: fix: [perl #39583] Pattern Match fails for specific length string
Message ID:
9b18b3110606230254m6afd620bjde6322aefda6f199@mail.gmail.com
On 6/23/06, via RT Erik R. Ogan <perlbug-followup@perl.org> wrote:
> # New Ticket Created by  "Erik R. Ogan"
> # Please include the string:  [perl #39583]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=39583 >
>
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> This is a bug report for perl from erik@cloudshield.com,
> generated with the help of perlbug 1.35 running under perl v5.8.5.
>
>
> - -----------------------------------------------------------------
> [Please enter your report here]
>
> *NOTE*NOTE* in spite of using the perlbug installed from an RPM,
> I've also reproduced this with locally built versions of v5.8.8 and
> v5.9.3.
>
> The following script produces an unexpected result. Changing the
> value of $size ((empirical evidence shows) to ANY other value)
> returns the expected behavior.
>
> - -cut-cut-cut-cut-cut-cut-cut-cut-
> #!/usr/bin/perl
>
> # The printing characters
> my @chars = ("\n", "\t", map {chr} 040..0177);
>
> # \376 also works, I haven't tried other values
> my $delim = "\0";
>
> # add a +1 or -1 (or change to any other value) to make this succeed.
> my $size = 32771 - 4;
>
> my $test = '';
>
> # create some random junk. Inefficient, but it works.
> for ($i = 0 ; $i < $size ; $i++) {
>     $test .= $chars[int(rand(@chars))];
> }
>
> $test .= ($delim x 4);
>
> $test =~ s/^(.*?)${delim}{4}//s;
>
> print "Should be empty: $test\n\n";
>
> print "Should be 0: ", length($test), "\n";
> print "Should be $size: ", length($1), "\n";

Attached patch fixes the problem.

We should probably convert the sample code to a test. Attached is a
modified version of the OP's test to use. I changed it to stay in the
"visible" range of characters as the re debug code doesnt play nicely
with control chars and nulls so you cant see whats going on.  Which in
itself should be a TODO as it should be possible to debug such cases.

Sorry i dont have time to do the test part right now.

cheers,
Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About