473
|
|
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]; }
|
Brian Fraser |
|
11 years ago
|
|
|
472
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
471
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
470
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
469
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
468
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
467
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
466
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
465
|
|
|
Daniel Nichter |
2.1.7 |
11 years ago
|
|
|
464
|
|
|
Daniel Nichter |
|
11 years ago
|
|
|
463
|
|
|
Daniel Nichter |
|
11 years ago
|
|
|
462
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
461
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
460
|
|
|
fraserb at gmail |
2.1.6 |
11 years ago
|
|
|
459
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
458
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
457
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
456
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
455
|
|
|
Brian Fraser |
|
11 years ago
|
|
|
454
|
|
|
Brian Fraser |
|
11 years ago
|
|
|