]> git.neil.brown.name Git - edlib.git/commitdiff
rexel: properly initialise ->link array
authorNeilBrown <neil@brown.name>
Tue, 16 May 2023 21:08:12 +0000 (07:08 +1000)
committerNeilBrown <neil@brown.name>
Fri, 26 May 2023 22:18:42 +0000 (08:18 +1000)
->link[x][0] wasn't being initialised.  I wonder how this ever works.
valgrind wonders why I never asked it before.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
rexel.c

index 029486b8cd7dec9dab21e5986037c1eb06b41475..e8335c48ccd21a07776175b35f4c4e19dd65cd14 100644 (file)
@@ -53,6 +53,7 @@ Current priorities
 Bugs to be fixed
 ----------------
 
+- [ ] search for "\s" loops infinitely.
 - [ ] email: urls should not be followed unless they are visible.
       Maybe display in the message window, which might be made larger
       just for this purpose.
diff --git a/rexel.c b/rexel.c
index e041989b7161feb8d0cd6067ff3c7a0ed61de22f..3c3caa12748c19253e0bfdb27218dc984e0b52a6 100644 (file)
--- a/rexel.c
+++ b/rexel.c
@@ -780,6 +780,8 @@ enum rxl_found rxl_advance(struct match_state *st safe, wint_t ch)
                                abort();
                        cnt += 1;
                        i = st->link[active][i];
+                       if (i >= len)
+                               abort();
                } while (i);
                for (i = 0; i < len; i++)
                        if (st->link[active][i] == NO_LINK ||
@@ -2120,6 +2122,10 @@ struct match_state *safe rxl_prepare(unsigned short *rxl safe, int flags)
        st->ignorecase = calloc(BITSET_SIZE(len), sizeof(*st->ignorecase));
        st->active = 0;
        st->match = -1;
+       if (!st->backtrack) {
+               st->link[0][0] = 0;
+               st->link[1][0] = 0;
+       }
        for (i = 1; i < len; i++) {
                if (rxl[i] == REC_IGNCASE)
                        ic = True;
@@ -2128,8 +2134,8 @@ struct match_state *safe rxl_prepare(unsigned short *rxl safe, int flags)
                if (ic)
                        set_bit(i, st->ignorecase);
                if (!st->backtrack) {
-                       st->link[0][i] = i ? NO_LINK : 0;
-                       st->link[1][i] = i ? NO_LINK : 0;
+                       st->link[0][i] = NO_LINK;
+                       st->link[1][i] = NO_LINK;
                }
        }