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