Skip to content

string: handle empty replace pattern - #141

Merged
tezc merged 1 commit into
tezc:masterfrom
94xhn:fix/string-empty-replace
Jul 17, 2026
Merged

string: handle empty replace pattern#141
tezc merged 1 commit into
tezc:masterfrom
94xhn:fix/string-empty-replace

Conversation

@94xhn

@94xhn 94xhn commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

sc_str_replace() passes an empty search pattern to strstr(). Since the pattern length is zero, neither replacement loop advances: the same-size path repeats indefinitely, while the resizing path repeats until the size guard rejects it.

Treat an empty search pattern as a successful no-op, consistent with the existing no-match behavior. Add coverage for both empty-to-nonempty and empty-to-empty replacements.

Tests:

  • official CMake sc_str_test with AddressSanitizer
  • GCC 13 with -Wall -Wextra -pedantic -Werror and ASan/UBSan
  • MinGW GCC 8 with strict warnings

An empty search pattern never advances either strstr loop. Treat it as a successful no-op, matching the existing no-match behavior.

Confidence: high

Scope-risk: narrow

Tested: official sc_str CMake test with ASan; GCC 13 ASan/UBSan; MinGW GCC 8

Not-tested: MSVC
@tezc
tezc merged commit f522219 into tezc:master Jul 17, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants