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.
This commit is contained in:
apio 2023-06-19 10:44:33 +02:00
parent ae01a31104
commit 0b553cadc0
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -503,15 +503,18 @@ usize vstring_format(char* buf, usize max, const char* format, va_list ap)
[](char c, void* arg) -> Result<void> {
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;
}