summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichael Brown2016-04-12 12:51:05 +0200
committerMichael Brown2016-04-12 12:53:06 +0200
commitcc8824ad4e9486b9fa64f1b1d078ff1963f71219 (patch)
tree2b170bde860ac5b91d44ddb9ad6a4fcbe605810b /src/core
parent[test] Update snprintf_ok() to use okx() (diff)
downloadipxe-cc8824ad4e9486b9fa64f1b1d078ff1963f71219.tar.gz
ipxe-cc8824ad4e9486b9fa64f1b1d078ff1963f71219.tar.xz
ipxe-cc8824ad4e9486b9fa64f1b1d078ff1963f71219.zip
[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>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/vsprintf.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/core/vsprintf.c b/src/core/vsprintf.c
index cb3bec5d..9d3a97c2 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 = "<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;