From b77e01a5d218c73ef7b0cff8ca18a57168a2ff7d Mon Sep 17 00:00:00 2001 From: antifallobst Date: Thu, 23 Feb 2023 11:22:33 +0100 Subject: [PATCH] feature (kernel): Implemented numeric_specifier feature for substrings in format strings --- kernel/src/utils/string.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/src/utils/string.c b/kernel/src/utils/string.c index b7a46b3..5ad49b0 100644 --- a/kernel/src/utils/string.c +++ b/kernel/src/utils/string.c @@ -64,7 +64,14 @@ uint64_t variadic_format_size(string_t string, va_list args) { } case 's': { // string - length += string_length(va_arg(args, string_t)); + uint64_t strlen = string_length(va_arg(args, string_t)); + if (numeric_specifier > 0) { + strlen = MIN(strlen, numeric_specifier); + } else { + strlen = numeric_specifier; + } + + length += strlen; break; } case 'c': { @@ -187,6 +194,12 @@ void variadic_format(string_t output, string_t string, va_list args) { string_t str = va_arg(args, string_t); uint64_t strlen = string_length(str); + if (numeric_specifier > 0) { + strlen = MIN(strlen, numeric_specifier); + } else { + strlen = numeric_specifier; + } + memory_copy((void*)str, buffer_out, strlen); buffer_out += strlen; break;