From cc8824ad4e9486b9fa64f1b1d078ff1963f71219 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 12 Apr 2016 11:51:05 +0100 Subject: [libc] Print "" for wide-character NULL strings The existing code intends to print NULL strings as "" (for the sake of debug messages), but the logic is incorrect when handling wide-character strings. Fix the logic and add applicable unit tests. Signed-off-by: Michael Brown --- src/core/vsprintf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/vsprintf.c b/src/core/vsprintf.c index cb3bec5dd..9d3a97c2d 100644 --- a/src/core/vsprintf.c +++ b/src/core/vsprintf.c @@ -257,11 +257,13 @@ size_t vcprintf ( struct printf_context *ctx, const char *fmt, va_list args ) { } else if ( *fmt == 's' ) { if ( length < &type_sizes[LONG_LEN] ) { ptr = va_arg ( args, char * ); + if ( ! ptr ) + ptr = ""; } else { wptr = va_arg ( args, wchar_t * ); + if ( ! wptr ) + ptr = ""; } - if ( ( ptr == NULL ) && ( wptr == NULL ) ) - ptr = ""; } else if ( *fmt == 'p' ) { intptr_t ptrval; -- cgit v1.2.3-55-g7522