win32/HResult: convert assert() to runtime check to work around -Walloc-size-larger-than

This commit is contained in:
Max Kellermann 2023-12-20 15:12:19 +01:00
parent a654c5d643
commit 6e6f72a521
1 changed files with 4 additions and 2 deletions

View File

@ -100,9 +100,11 @@ FormatHResultError(HRESULT result, const char *fmt, ...) noexcept
va_start(args1, fmt); va_start(args1, fmt);
va_copy(args2, args1); va_copy(args2, args1);
const int size = vsnprintf(nullptr, 0, fmt, args1); int size = vsnprintf(nullptr, 0, fmt, args1);
va_end(args1); va_end(args1);
assert(size >= 0);
if (size < 0)
size = 0;
auto buffer = std::make_unique<char[]>(size + 1); auto buffer = std::make_unique<char[]>(size + 1);
vsprintf(buffer.get(), fmt, args2); vsprintf(buffer.get(), fmt, args2);