Skip to content

Commit ef73155

Browse files
tpamborjhedberg
authored andcommitted
ztest: Add validation of zassert strings
Add __printf_like attribute to ztest assertion functions zassert, zassume, zexpect to validate format strings and arguments at compile time. Signed-off-by: Tim Pambor <[email protected]>
1 parent e3c5bdf commit ef73155

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

subsys/testsuite/ztest/include/zephyr/ztest_assert.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ static inline bool z_zexpect_(bool cond, const char *file, int line)
7676

7777
#else /* CONFIG_ZTEST_ASSERT_VERBOSE != 0 */
7878

79-
static inline bool z_zassert(bool cond, const char *default_msg, const char *file, int line,
80-
const char *func, const char *msg, ...)
79+
static inline __printf_like(6, 7) bool z_zassert(bool cond, const char *default_msg,
80+
const char *file, int line, const char *func,
81+
const char *msg, ...)
8182
{
8283
if (cond == false) {
8384
va_list vargs;
@@ -100,8 +101,9 @@ static inline bool z_zassert(bool cond, const char *default_msg, const char *fil
100101
return true;
101102
}
102103

103-
static inline bool z_zassume(bool cond, const char *default_msg, const char *file, int line,
104-
const char *func, const char *msg, ...)
104+
static inline __printf_like(6, 7) bool z_zassume(bool cond, const char *default_msg,
105+
const char *file, int line, const char *func,
106+
const char *msg, ...)
105107
{
106108
if (cond == false) {
107109
va_list vargs;
@@ -124,8 +126,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
124126
return true;
125127
}
126128

127-
static inline bool z_zexpect(bool cond, const char *default_msg, const char *file, int line,
128-
const char *func, const char *msg, ...)
129+
static inline __printf_like(6, 7) bool z_zexpect(bool cond, const char *default_msg,
130+
const char *file, int line, const char *func,
131+
const char *msg, ...)
129132
{
130133
if (cond == false) {
131134
va_list vargs;

0 commit comments

Comments
 (0)