From 0b553cadc02d1282b7c345e76718c6f0f2304340 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 19 Jun 2023 10:44:33 +0200 Subject: [PATCH] libluna: Do not fault if vstring_format() is called with buf=nullptr Instead, just discard the output and return the number of bytes formatted, as mandated by the C standard. --- libluna/src/Format.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libluna/src/Format.cpp b/libluna/src/Format.cpp index 1754942c..3fed3ca0 100644 --- a/libluna/src/Format.cpp +++ b/libluna/src/Format.cpp @@ -503,15 +503,18 @@ usize vstring_format(char* buf, usize max, const char* format, va_list ap) [](char c, void* arg) -> Result { StringFormatInfo* info_arg = (StringFormatInfo*)arg; if (!info_arg->remaining) return {}; - *(info_arg->buffer) = c; - info_arg->buffer++; + if (info_arg->buffer) + { + *(info_arg->buffer) = c; + info_arg->buffer++; + } info_arg->remaining--; return {}; }, &info, ap) .value(); - *(info.buffer) = 0; + if (info.buffer) *(info.buffer) = 0; return result; }