Commit d462a8ff

d462a8ff2417Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(regexp): grow thread list on demand instead of dropping (#756)

When list->count >= list->capa, the previous code silently dropped the new thread. On patterns with many simultaneous alternatives (e.g. a|b|c|...|z) this produced false negatives: the match was real but the dropped thread never got to consume it.

Grow the array via realloc (double the capa). On OOM, fall back to the old drop-and-continue behaviour so we degrade rather than crashing.

Closes #756

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
d462a8ff2417
Parent
e8db1839a6ff

lib/regexp/re_exec.cmodifiedView file

@@ -203,12 +203,21 @@
203203 break;
204204 }
205205
206- if (list->count < list->capa) {
207- re_thread *t = &list->threads[list->count++];
208- t->pc = pc;
209- t->cap_slot = cap_slot;
210- t->sp = sp;
206+ /* Issue #756: grow the thread list on demand instead of silently
207+ dropping the new thread. The previous form produced false
208+ negatives on patterns with many simultaneous alternatives. */
209+ if (list->count >= list->capa) {
210+ int new_capa = list->capa * 2;
211+ re_thread *nt = (re_thread *)realloc(list->threads,
212+ sizeof(re_thread) * new_capa);
213+ if (!nt) return; /* OOM: drop the thread, same as before */
214+ list->threads = nt;
215+ list->capa = new_capa;
211216 }
217+ re_thread *t = &list->threads[list->count++];
218+ t->pc = pc;
219+ t->cap_slot = cap_slot;
220+ t->sp = sp;
212221 }
213222
214223 static int