Skip to content

Avoid GCC 16 -Wstringop-overflow false positive in NxsString - #24

Merged
fmichonneau merged 1 commit into
mainfrom
fix-gcc16-stringop-overflow
Jul 31, 2026
Merged

Avoid GCC 16 -Wstringop-overflow false positive in NxsString#24
fmichonneau merged 1 commit into
mainfrom
fix-gcc16-stringop-overflow

Conversation

@fmichonneau

Copy link
Copy Markdown
Owner

GCC 16.1's tightened -Wstringop-overflow analysis flags a __builtin_memmove "writing into a region of size 0" inlined from std::char_traits::copy, triggered by the append(std::string(...)) pattern in NxsString::operator+= (reported by CRAN gcc-SAN checks).

Rewrite the two suspect overloads to avoid constructing a temporary std::string before appending:

  • operator+=(const char *): append(s) directly
  • operator+=(const char c): push_back(c)

Both are behavior-preserving and drop the char_traits::copy-from-a- bounded-buffer path that the analyzer mis-reasons about.

GCC 16.1's tightened -Wstringop-overflow analysis flags a
__builtin_memmove "writing into a region of size 0" inlined from
std::char_traits<char>::copy, triggered by the append(std::string(...))
pattern in NxsString::operator+= (reported by CRAN gcc-SAN checks).

Rewrite the two suspect overloads to avoid constructing a temporary
std::string before appending:
- operator+=(const char *): append(s) directly
- operator+=(const char c): push_back(c)

Both are behavior-preserving and drop the char_traits::copy-from-a-
bounded-buffer path that the analyzer mis-reasons about.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@fmichonneau
fmichonneau merged commit c8884fa into main Jul 31, 2026
9 checks passed
@fmichonneau
fmichonneau deleted the fix-gcc16-stringop-overflow branch July 31, 2026 05:45
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.

1 participant