nasmlib/asprintf: check the return value from vsnprintf()

Without this, gcc may throw a warning which breaks the --enable-werror
build. It is good practice anyway...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2025-08-25 20:06:04 -07:00
parent ada267ec8c
commit 0b73367874
2 changed files with 8 additions and 4 deletions

View file

@ -52,15 +52,19 @@ void *nasm_vaxprintf(size_t extra, const char *fmt, va_list ap)
char *strp;
va_list xap;
size_t bytes;
int len;
va_copy(xap, ap);
bytes = vsnprintf(NULL, 0, fmt, xap) + 1;
len = vsnprintf(NULL, 0, fmt, xap);
nasm_assert(len >= 0);
bytes = (size_t)len + 1;
_nasm_last_string_size = bytes;
va_end(xap);
strp = nasm_malloc(extra+bytes);
memset(strp, 0, extra);
vsnprintf(strp+extra, bytes, fmt, ap);
len = vsnprintf(strp+extra, bytes, fmt, ap);
nasm_assert(bytes == (size_t)len + 1);
return strp;
}