~percona-toolkit-dev/percona-toolkit/fix-929046-pt-qa-sub.001-lit.001-lit.002-fix

Viewing all changes in revision 473.

  • Committer: Brian Fraser
  • Date: 2012-12-03 03:17:39 UTC
  • Revision ID: brian.fraser@percona.com-20121203031739-mls0481lg72bwzkw
Fix for bug 929046: SUB.001, LIT.001 and LIT.002 are sensitive to program state

The original bug was about SUB.001, but LIT.00[12] were affected
as well. The bug boiled down to using //g on $event->{arg}, but
here's a simplified version:

        my $str = "abc in stuff";
        # This will print "6"
        say $str =~ /in/g  ? pos($str) : "no match";
        # This will print "no match"
        say $str =~ /abc/g ? pos($str) : "no match";

The second doesn't match because it will start from after
the "in" that the previous regex matched, at which point
it's too late to match abc.

There's two solutions to this: First, to use lvalue pos() before
each match, ala pos($str) = 0; -- But that's doing a lot of
extra stuff to work around our own bug. The other solution,
and what this commit implements, is not using //g and pos() at all,
instead using the @+ variable. $+[0] already holds the data we need,
at no extra cost, and to boot makes things slightly faster.

So what was previously

        if ( $str =~ m/./g ) {
          return pos($str)
        }

Is now

        if ( $str =~ m/./ ) {
          return $+[0];
        }

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: