aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2022-03-24 14:42:16 +0000
committerTor Brede Vekterli <vekterli@yahooinc.com>2022-03-24 14:42:16 +0000
commit7d446c3a37f7583b7e8e720f8e0ff0b1ed3dd274 (patch)
treebf89c4efb6f136df6941400668c4df59a9ee5d2f
parent51346c0606f7d859baf5b6aee1395e1926821d0a (diff)
Make it obvious to the compiler that nullptr format string is not possible
-rw-r--r--fastos/src/tests/threadtest.cpp3
-rw-r--r--vespalib/src/vespa/vespalib/data/slime/strfmt.h4
2 files changed, 5 insertions, 2 deletions
diff --git a/fastos/src/tests/threadtest.cpp b/fastos/src/tests/threadtest.cpp
index de1e15de2b3..968779019cb 100644
--- a/fastos/src/tests/threadtest.cpp
+++ b/fastos/src/tests/threadtest.cpp
@@ -28,6 +28,9 @@ class ThreadTest : public ThreadTestBase
for (i=0; i<MAX_THREADS+1; i++) {
jobs[i].code = WAIT_FOR_BREAK_FLAG;
jobs[i].message = static_cast<char *>(malloc(100));
+ if (jobs[i].message == nullptr) {
+ abort(); // GCC may infer that a potentially null ptr is passed to sprintf
+ }
sprintf(jobs[i].message, "Thread %d invocation", i+1);
}
diff --git a/vespalib/src/vespa/vespalib/data/slime/strfmt.h b/vespalib/src/vespa/vespalib/data/slime/strfmt.h
index e1a24ce505d..01e60eac3c0 100644
--- a/vespalib/src/vespa/vespalib/data/slime/strfmt.h
+++ b/vespalib/src/vespa/vespalib/data/slime/strfmt.h
@@ -8,8 +8,8 @@ namespace vespalib::slime {
extern std::string strfmt(const char *fmt, ...)
#ifdef __GNUC__
- // Add printf format checks with gcc
- __attribute__ ((format (printf,1,2)))
+ __attribute__ ((format (printf,1,2))) // Add printf format checks with gcc
+ __attribute__((nonnull(1))) // Format string can never be null
#endif
;