From a6af38bb397f984f4b83822e684964bec2e98200 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Sat, 11 Mar 2023 11:23:53 +0100 Subject: [PATCH] feature (string utils): replacing NULL reference strings in format with warning --- kernel/src/utils/string.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/src/utils/string.c b/kernel/src/utils/string.c index ec3bcd6..79fba97 100644 --- a/kernel/src/utils/string.c +++ b/kernel/src/utils/string.c @@ -71,7 +71,12 @@ uint64_t variadic_format_size(string_t string, va_list args) { } case 's': { // string - uint64_t strlen = string_length(va_arg(args, string_t)); + string_t str = va_arg(args, string_t); + if (str == NULL) { + str = ""; + } + + uint64_t strlen = string_length(str); if (numeric_specifier > 0) { strlen = MIN(strlen, numeric_specifier); } @@ -201,7 +206,10 @@ void variadic_format(string_t output, string_t string, va_list args) { } case 's': { // string - string_t str = va_arg(args, string_t); + string_t str = va_arg(args, string_t); + if (str == NULL) { + str = ""; + } uint64_t strlen = string_length(str); if (numeric_specifier > 0) {