Skip to content

Commit 9f5492a

Browse files
tpambordanieldegrasse
authored andcommitted
sys: cbprintf: Fix performance-no-int-to-ptr warning
clang-tidy reports a performance-no-int-to-ptr warning due to the cast (const char *)(uintptr_t)(v). Previously, only char * was cast to const char *, but there's no downside to constifying all pointer types. This change updates the Z_CONSTIFY macro to apply const consistently, which even aligns better with its name and resolves the warning. Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
1 parent 6aeb12d commit 9f5492a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/zephyr/sys/cbprintf_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,11 @@ extern "C" {
560560
#ifdef __cplusplus
561561
#define Z_CBPRINTF_ARG_SIZE(v) z_cbprintf_cxx_arg_size(v)
562562
#else
563-
#define Z_CONSTIFY(v) (_Generic((v), char * : (const char *)(uintptr_t)(v), default : (v)))
563+
#define Z_CONSTIFY(v) ({ \
564+
__auto_type _uv = (v); \
565+
__typeof__(_uv) const _cv = _uv; \
566+
_cv; \
567+
})
564568
#define Z_CBPRINTF_ARG_SIZE(v) ({\
565569
__auto_type __v = Z_ARGIFY(Z_CONSTIFY(v)); \
566570
/* Static code analysis may complain about unused variable. */ \

0 commit comments

Comments
 (0)