From a266663f88dd24747f450b98bd54010a386c4be7 Mon Sep 17 00:00:00 2001 From: rosenrost <52100845+rosenrost@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:43:50 +0100 Subject: [PATCH] Don't use a va_list twice in vasprintf() vasprintf() passed the same va_list to vsnprintf() twice. After the first use its value is indeterminate; it only worked by chance with the m68k calling convention. Use a copy for the first pass. --- sources/vasprintf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sources/vasprintf.c b/sources/vasprintf.c index bec9a65..4050879 100644 --- a/sources/vasprintf.c +++ b/sources/vasprintf.c @@ -8,7 +8,13 @@ int vasprintf(char** strp, const char* format, va_list ap) { - int size = vsnprintf(NULL, 0, format, ap); + va_list ap2; + int size; + + /* the argument list is traversed twice */ + __va_copy(ap2, ap); + size = vsnprintf(NULL, 0, format, ap2); + va_end(ap2); if (size >= 0 && size < INT_MAX) { *strp = malloc(size + 1);