Skip to content

[fix][test] Fix GCC -Werror=stringop-truncation in MessageTest - #622

Open
davlgd wants to merge 1 commit into
apache:mainfrom
davlgd:davlgd-fix-messagetest-stringop-truncation
Open

davlgd wants to merge 1 commit into
apache:mainfrom
davlgd:davlgd-fix-messagetest-stringop-truncation

Conversation

@davlgd

@davlgd davlgd commented Oct 31, 2026

Copy link
Copy Markdown

Fixes #621

Motivation

With GCC 15.3.0 and 16.2.1 at -O2, testAllocatedContents in tests/MessageTest.cc fails to compile under the project's -Werror setting. It uses strncpy to copy str.length() bytes, omitting the terminating NUL. The test passes the buffer with an explicit byte count, so a NUL terminator is not required: memcpy expresses the intended byte copy without triggering -Wstringop-truncation.

Modifications

Replace strncpy with memcpy for the same str.length() bytes. The content and length passed to the message are unchanged.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as MessageTest.testAllocatedContents, which builds and passes with the change.

Documentation

  • doc-not-needed
    (Only the setup of an existing test changes; no public API or user-facing behavior changes.)

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.

[Bug] MessageTest fails to build with GCC 15.3.0 and 16.2.1 (-Werror=stringop-truncation)

1 participant