json_print: add NULL check before jsonw_string_field() in print_string()
Static analyzer (Svace) reported a potential null pointer dereference
in print_string(). Specifically, when both 'key' and 'value' are NULL,
the function falls through to jsonw_string_field(_jw, key, value),
which dereferences both pointers.
Although comments suggest this case is unlikely, it is safer to
explicitly guard against it. This patch adds a check to ensure
both key and value are non-NULL before passing to jsonw_string_field().
This resolves:
DEREF_AFTER_NULL: json_print.c:142
Found by Svace static analysis tool.
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
1 file changed