From fd4db67b43bfffded2b20ec5665924f3b663c3e7 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Thu, 4 Apr 2019 06:31:25 -0600 Subject: [PATCH] libs/libc/stdio/lib_libvsprintf.c: Restore support for printing NULL string as "(null)". Legacy printf supported printing "(null)" in place for NULL string: printf("null: %s\n", NULL); => null: (null). This commit restores this functionality for new printf library. --- libs/libc/stdio/lib_libvsprintf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/libc/stdio/lib_libvsprintf.c b/libs/libc/stdio/lib_libvsprintf.c index a5e0ae3ec8..5076697adf 100644 --- a/libs/libc/stdio/lib_libvsprintf.c +++ b/libs/libc/stdio/lib_libvsprintf.c @@ -136,6 +136,12 @@ struct arg } value; }; + /**************************************************************************** + * Private Constant Data + ****************************************************************************/ + + static const char g_nullstring[] = "(null)"; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -847,6 +853,11 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream, #else pnt = va_arg(ap, FAR char *); #endif + if (pnt == NULL) + { + pnt = g_nullstring; + } + size = strnlen(pnt, (flags & FL_PREC) ? prec : ~0); str_lpad: