Skip to content

Conversation

tpambor
Copy link
Contributor

@tpambor tpambor commented Sep 21, 2025

Add __printf_like attribute to ztest assertion functions zassert, zassume, zexpect to validate format strings and arguments at compile time.

This also fixes the following warnings when compiling with clang (found while testing new zephyr sdk 0.18.0-alpha4):

zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h:88:11: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
   88 |                 vprintk(msg, vargs);
      |                         ^~~
zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h:112:11: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
  112 |                 vprintk(msg, vargs);
      |                         ^~~
zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h:136:11: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
  136 |                 vprintk(msg, vargs);
      |                         ^~~

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 <tim.pambor@codewrights.de>
strlen returns size_t, not int. Fix the format specifier to avoid warnings
when building with -Wformat.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Use %lx for printing addresses (uintptr_t) instead of %x.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Copy link

@jhedberg jhedberg merged commit e213815 into zephyrproject-rtos:main Oct 2, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants