Commit 1a2c223c

1a2c223cb598Merged

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

Description

fix(runtime): silence -Wstringop-overflow on sp_re_last_str init

The other regex globals (sp_re_captures, sp_re_match_str / _pre / _post) are NULL-initialized; sp_re_last_str alone was set to the rodata literal "". sp_mark_string's null guard treats both identically at runtime — the byte at s[-1] is read, the if guard fails for non-heap strings, no write happens. But gcc -O3 with the helper inlined at sp_re_mark_globals's call site sees the literal "" of size 1 and the conditional s[-1] = 0xfc write, proves the write is out of bounds, and warns regardless of the guard.

NULL-init aligns sp_re_last_str with its siblings and skips the s[-1] access path entirely. No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
1a2c223cb598
Parent
3a7e10d72e45

lib/sp_runtime.hmodifiedView file

@@ -582,7 +582,13 @@
582582 /* Regexp globals: $1-$9 captures */
583583 static const char *sp_re_captures[10] = {0};
584584 static int sp_re_caps[64];
585-static const char *sp_re_last_str = "";
585+/* NULL (not "") so sp_mark_string's null-guard handles the unset case
586+ without reaching the `s[-1]` access. The rodata `""` literal would
587+ trigger -Wstringop-overflow under -O3 + sp_mark_string inlining at
588+ the call site in sp_re_mark_globals — gcc proves the `s[-1] = 0xfc`
589+ write would be out-of-bounds even though the runtime guard
590+ `s[-1] == 0xfe` (always false for rodata) prevents it from firing. */
591+static const char *sp_re_last_str = NULL;
586592
587593 /* Symbolic back-references populated alongside the numbered captures.
588594 Read by codegen's BackReferenceReadNode arm: