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

オープン
#621 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@davlgd がすでに取り組んでいます。

2026年10月31日 から。

  • #622 @davlgd による — オープン

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
cmake, cpp
領域
testing

調査の方向性

The warning comes from testAllocatedContents in tests/MessageTest.cc around line 53, where strncpy copies str.length() bytes. Check the setAllocatedContent() call and the msg.getLength() comparison that follow. A linked pull request (#622) is already open against this issue, so review that first. Done means the MessageTest.* tests build under the top-level -Werror and pass.

索引モデルが issue の本文から書いたものです。

説明

Search before asking
  • I searched in the issues and found nothing similar.
Version

pulsar-client-cpp 4.2.0 on Exherbo Linux (x86_64), built with GCC 15.3.0, -O2 and -DBUILD_TESTS=ON. Also reproduced on Arch Linux with GCC 16.2.1 and protobuf 36.1; there, the build used -Wno-error=unused-result to get past a separate protobuf build failure, with -Werror=stringop-truncation still enabled. The same call is present on main at f71d7e99019d58b1d11858f05ff0dc83b718627b (source inspection).

Minimal reproduce step

With the dependencies installed and GCC 15.3.0:

cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_CXX_FLAGS=-O2
cmake --build build

On Arch Linux (GCC 16.2.1, protobuf 36.1):

cmake -S . -B build-arch -DBUILD_TESTS=ON "-DCMAKE_CXX_FLAGS=-O2 -Wno-error=unused-result" -DCMAKE_C_FLAGS=-O2
cmake --build build-arch --target pulsar-tests

The top-level CMakeLists.txt adds -Werror, so tests/MessageTest.cc fails to compile. Failing build log: https://gitlab.exherbo.org/davlgd/CleverCloud/-/jobs/223191

What did you expect to see?

The tests build.

What did you see instead?
tests/MessageTest.cc:53:12: error: 'char* strncpy(char*, const char*, size_t)' output truncated before terminating nul copying 7 bytes from a string of the same length [-Werror=stringop-truncation]
   53 |     strncpy(content, str.c_str(), str.length());
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
Anything else?

testAllocatedContents copies str.length() bytes with strncpy, so the terminating NUL is never written. No NUL terminator is required in this test: setAllocatedContent() takes a pointer and an explicit byte count, and the comparison is bounded by msg.getLength(). GCC's documentation uses this strncpy(d, s, strlen(s)) pattern as its example for this warning and suggests memcpy instead. With strncpy replaced by memcpy for the same byte count, all 10 MessageTest.* tests passed on Arch Linux with GCC 16.2.1 and -O2 -Wno-error=unused-result.

Are you willing to submit a PR?
  • I'm willing to submit a PR!
主要言語
C++
スター
72
フォーク
93
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/pulsar-client-cpp のほかの issue

apache/pulsar-client-cpp の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。