bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#58726: 29.0.50; Bug in regexp matching with shy groups


From: Mattias Engdegård
Subject: bug#58726: 29.0.50; Bug in regexp matching with shy groups
Date: Sun, 23 Oct 2022 15:50:41 +0200

Michael, thank you for finding this amusing bug!

>   (string-match-p "\\`\\(?:ab\\)*\\'" "a") ==> 0

With a bit of help from the regexp-disasm package, we see that this compiles to

    0  begbuf
    1  on-failure-jump-smart to 11
    4  exact "ab"
    8  jump to 1
   11  endbuf
   12  succeed

where the on-failure-jump-smart op turns into on-failure-keep-string-jump the 
first time it's executed.

This gives us a clue about what is wrong: when there is a failure inside an 
'exact' string match, the target pointer should be reset to the start of that 
string ("ab" here) before jumping to the failure location.

Reading the source it becomes clear that this is done correctly when there is a 
mismatch, but not if the target string ends prematurely because PREFETCH() has 
no idea that it should reset the target pointer! Easy enough to fix.

Please try the attached patch. (The patch takes care of counted repetitions for 
good measure although I wasn't able to provoke a failure directly.)

Attachment: 0001-Fix-regexp-matching-with-atomic-strings-and-optimise.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]