[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master e88be844bf7: regex.c (mutually_exclusive_p): Fix initial value of
From: |
Stefan Monnier |
Subject: |
master e88be844bf7: regex.c (mutually_exclusive_p): Fix initial value of `loop_beg` |
Date: |
Tue, 26 Sep 2023 11:44:02 -0400 (EDT) |
branch: master
commit e88be844bf774b336ab67995e435416328b53776
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
regex.c (mutually_exclusive_p): Fix initial value of `loop_beg`
* src/regex-emacs.c (mutually_exclusive_p): Don't pretend that pattern
position 0 has been checked already.
* test/src/regex-emacs-tests.el (regexp-tests-backtrack-optimization):
Add a corresponding regression test plus some other related tests
I had around.
---
src/regex-emacs.c | 2 +-
test/src/regex-emacs-tests.el | 20 +++++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/regex-emacs.c b/src/regex-emacs.c
index cf7b704ee95..338323cf79e 100644
--- a/src/regex-emacs.c
+++ b/src/regex-emacs.c
@@ -3941,7 +3941,7 @@ static bool
mutually_exclusive_p (struct re_pattern_buffer *bufp, re_char *p1,
re_char *p2)
{
- return mutually_exclusive_aux (bufp, p1, p2, bufp->buffer, NULL);
+ return mutually_exclusive_aux (bufp, p1, p2, bufp->buffer - 1, NULL);
}
/* Matching routines. */
diff --git a/test/src/regex-emacs-tests.el b/test/src/regex-emacs-tests.el
index f2bee713864..c84998e1184 100644
--- a/test/src/regex-emacs-tests.el
+++ b/test/src/regex-emacs-tests.el
@@ -878,10 +878,28 @@ This evaluates the TESTS test cases from glibc."
(erase-buffer)
(insert (make-string 1000000 ?x) "=")
(goto-char (point-min))
+ ;; Make sure we do perform the optimization (if we don't, the
+ ;; below will burp with regexp-stack-overflow).
(should (looking-at "x*=*"))
(should (looking-at "x*\\(=\\|:\\)"))
(should (looking-at "x*\\(=\\|:\\)*"))
- (should (looking-at "x*=*?"))))
+ (should (looking-at "x*=*?"))
+ (should (looking-at "x*\\(=*\\|h\\)*?"))
+ (should (looking-at "x*\\(=*\\|h\\)*"))
+ (should (looking-at "x*\\(=*?\\|h\\)*"))
+ (should (looking-at "x*\\(=*?\\|h\\)*?"))
+ (should (looking-at "x*\\(=*\\|h\\)+?"))
+ (should (looking-at "x*\\(=*\\|h\\)+"))
+ (should (looking-at "x*\\(=*?\\|h\\)+"))
+ (should (looking-at "x*\\(=*?\\|h\\)+?"))
+ (should (looking-at "x*\\(=+\\|h\\)+?"))
+ (should (looking-at "x*\\(=+\\|h\\)+"))
+ (should (looking-at "x*\\(=+?\\|h\\)+"))
+ (should (looking-at "x*\\(=+?\\|h\\)+?"))
+ ;; Regression check for overly optimistic optimization.
+ (should (eq 0 (string-match "\\(ca*\\|ab\\)+d" "cabd")))
+ (should (string-match "\\(aa*\\|b\\)*c" "ababc"))
+ ))
(ert-deftest regexp-tests-zero-width-assertion-repetition ()
;; Check compatibility behaviour with repetition operators after
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master e88be844bf7: regex.c (mutually_exclusive_p): Fix initial value of `loop_beg`,
Stefan Monnier <=