From 8b627431703c7e7d762f9e3174336d66b558314a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 13 Apr 2026 13:26:58 -0700 Subject: [PATCH] regex: omit unnecessary check_halt_state_context * lib/regexec.c (prune_impossible_nodes): Avoid unnecessary call to check_halt_state_context. Suggested by Florian Weimer in: https://sourceware.org/pipermail/libc-alpha/2026-April/176627.html --- ChangeLog | 8 ++++++++ lib/regexec.c | 21 ++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 875e734657..98ad290692 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-04-13 Paul Eggert + + regex: omit unnecessary check_halt_state_context + * lib/regexec.c (prune_impossible_nodes): + Avoid unnecessary call to check_halt_state_context. + Suggested by Florian Weimer in: + https://sourceware.org/pipermail/libc-alpha/2026-April/176627.html + 2026-04-13 Bruno Haible regex: Fix use of uninitialized variable (regression yesterday). diff --git a/lib/regexec.c b/lib/regexec.c index 7095c4bf5b..65d4d0f09e 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -1013,7 +1013,7 @@ prune_impossible_nodes (re_match_context_t *mctx) goto free_return; if (sifted_states[0] != NULL || lim_states[0] != NULL) break; - do + for (;;) { --match_last; if (match_last < 0) @@ -1021,14 +1021,17 @@ prune_impossible_nodes (re_match_context_t *mctx) ret = REG_NOMATCH; goto free_return; } - } while (mctx->state_log[match_last] == NULL - || !mctx->state_log[match_last]->halt - || !check_halt_state_context (mctx, - mctx->state_log[match_last], - match_last)); - halt_node = check_halt_state_context (mctx, - mctx->state_log[match_last], - match_last); + if (mctx->state_log[match_last] != NULL + && mctx->state_log[match_last]->halt) + { + halt_node + = check_halt_state_context (mctx, + mctx->state_log[match_last], + match_last); + if (halt_node) + break; + } + } } ret = merge_state_array (dfa, sifted_states, lim_states, match_last + 1); -- 2.53.0