Skip to content
Commit f9a54755 authored by Krzysztof Chruściński's avatar Krzysztof Chruściński Committed by Carles Cufi
Browse files

sys: cbprintf: Add macro for validating strings for packaging



When cbprintf package is created statically then only argument
types are taken into account and not the format string. It means that a
character pointer is always interpreted as %s and not %p. When %s is
found then string from rw location is copied into the package.
Copying unexpected data may lead to memory faults so it must
be avoided. User shall cast an argument to a pointer of a different
type.

Patch adds macros which can at compile time determine if %p is
used with char *. Result cannot be passed to static assert because
compiler sees it as non-constant (even though calculated at compile
time) but a runtime logging error message can be added instead of
original message.

Z_CBPRINTF_NONE_CHAR_PTR_COUNT counts number of none character
pointers in the arguments list.
Z_CBPRINTF_P_COUNT counts number of %p occurrences in the format
string. If results of both macros are equal it means that string
is ok.

Signed-off-by: default avatarKrzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
parent 2a9f914d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment