]> git.eshelyaron.com Git - emacs.git/commitdiff
* src/regex-emacs.c (forall_firstchar_1): Improve corner case
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 22 Jan 2024 20:06:24 +0000 (15:06 -0500)
committerEshel Yaron <me@eshelyaron.com>
Wed, 24 Jan 2024 18:31:51 +0000 (19:31 +0100)
Fixes a "FORALL_FIRSTCHAR: Broken assumption2!!" warning with:

    "^\\(# *\\)\\([^ ]+?\\) *: *\\(.*?\\(?:\n\\1[ \t]+.*?\\)*\\)[[:space:]]*$"

(cherry picked from commit f821ac29e0cf69316d6c721bafe9b749b47a6db3)

src/regex-emacs.c

index dfc6c1fd691d604024854f7f29878e87e3497a0d..0ec0c6eb63f813e282855df224c21d868a02611c 100644 (file)
@@ -2923,8 +2923,18 @@ forall_firstchar_1 (re_char *p, re_char *pend,
                forward over a subsequent `jump`.  Recognize this pattern
                since that subsequent `jump` is the one that jumps to the
                loop-entry.  */
-           newp2 = ((re_opcode_t) *newp2 == jump)
-                   ? extract_address (newp2 + 1) : newp2;
+           if ((re_opcode_t) *newp2 == jump)
+             {
+               re_char *p3 = extract_address (newp2 + 1);
+               /* Only recognize this pattern if one of the two destinations
+                  is going forward, otherwise we'll fall into the pessimistic
+                  "Both destinations go backward" below.
+                  This is important if the `jump` at newp2 is the end of an
+                  outer loop while the `on_failure_jump` is the end of an
+                  inner loop.  */
+               if (p3 > p_orig || newp1 > p_orig)
+                 newp2 = p3;
+             }
 
          do_twoway_jump:
            /* We have to check that both destinations are safe.