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> { [](char c, void* arg) -> Result<void> {
StringFormatInfo* info_arg = (StringFormatInfo*)arg; StringFormatInfo* info_arg = (StringFormatInfo*)arg;
if (!info_arg->remaining) return {}; if (!info_arg->remaining) return {};
*(info_arg->buffer) = c; if (info_arg->buffer)
info_arg->buffer++; {
*(info_arg->buffer) = c;
info_arg->buffer++;
}
info_arg->remaining--; info_arg->remaining--;
return {}; return {};
}, },
&info, ap) &info, ap)
.value(); .value();
*(info.buffer) = 0; if (info.buffer) *(info.buffer) = 0;
return result; return result;
} }