[libc] Print "<NULL>" for wide-character NULL strings

The existing code intends to print NULL strings as "<NULL>" (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 <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2016-04-12 11:51:05 +01:00
parent 320488d0f9
commit cc8824ad4e
2 changed files with 8 additions and 2 deletions

View File

@@ -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 = "<NULL>";
} else {
wptr = va_arg ( args, wchar_t * );
if ( ! wptr )
ptr = "<NULL>";
}
if ( ( ptr == NULL ) && ( wptr == NULL ) )
ptr = "<NULL>";
} else if ( *fmt == 'p' ) {
intptr_t ptrval;