[Bug] MessageTest fails to build with GCC 15.3.0 and 16.2.1 (-Werror=stringop-truncation)
Bewertung
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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!
- Vorherrschende Sprache
- C++
- Sterne
- 72
- Forks
- 93
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus apache/pulsar-client-cpp
-
Schwierigkeit 3/5 Ein halber Tag Anfängerfreundlichkeit 62/100
apache/pulsar-client-cpp#623 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
apache/pulsar-client-cpp#620 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
apache/pulsar-client-cpp#619 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 20/100
apache/pulsar-client-cpp#618 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
apache/pulsar-client-cpp#617 ·
Alle Issues in apache/pulsar-client-cpp
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
NVIDIA-RTX/NRI#307 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100