tiny-printf: handle NULL pointer for %s format string
PATCH v2 1/1 tiny-printf: handle NULL pointer for %s format string
From: Anton Moryakov <[email protected]>
Avoid NULL pointer dereference in string formatting by printing "(null)" when a NULL pointer is passed to a %s format specifier.
This change makes the behavior consistent with standard printf() implementations and prevents potential crashes in constrained environments.
Signed-off-by Anton Moryakov <[email protected]>
--- lib/tiny-printf.c | 2 ++ 1 file changed, 2 insertions(+)
lib/tiny-printf.c +2 -0
@@ -307,6 +307,8 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va)break ;case 's' : p = va_arg(va, char*); +if (!p) + p ="(null)" ;break ;case '%' :out (info,'%' );
Signature · 1 line
2.34.1