From f815580dde2de9667af5ca8b43f9590f2fac1aab Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 28 Jun 2022 13:09:38 +0200 Subject: [PATCH] Fix SIGSEV in SDL_error. Re-apply same pattern on this uncompiled code (see #5795) --- src/dynapi/SDL_dynapi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c index 994a2c285..19eaf2a0f 100644 --- a/src/dynapi/SDL_dynapi.c +++ b/src/dynapi/SDL_dynapi.c @@ -73,13 +73,17 @@ static void SDL_InitDynamicAPI(void); _static int SDLCALL SDL_SetError##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \ char buf[128], *str = buf; \ int result; \ - va_list ap; initcall; va_start(ap, fmt); \ + va_list ap; initcall; \ + va_start(ap, fmt); \ result = jump_table.SDL_vsnprintf(buf, sizeof(buf), fmt, ap); \ + va_end(ap); \ if (result >= 0 && (size_t)result >= sizeof(buf)) { \ size_t len = (size_t)result + 1; \ str = (char *)jump_table.SDL_malloc(len); \ if (str) { \ + va_start(ap, fmt); \ result = jump_table.SDL_vsnprintf(str, len, fmt, ap); \ + va_end(ap); \ } \ } \ va_end(ap); \