From 86b84214b1520d9f2114387af9ec62598577bb4e Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Thu, 20 Feb 2025 17:30:51 -0600
Subject: [PATCH] error: Simplify SDL_SetError() by using SDL_SetErrorV()
---
src/sdl2_compat.c | 13 +------------
src/sdl3_syms.h | 1 +
2 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 001ffad..95bd092 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -1217,23 +1217,12 @@ SDL_GetErrorMsg(char *errstr, int maxlen)
SDL_DECLSPEC int SDLCALL
SDL_SetError(const char *fmt, ...)
{
- char ch;
- char *str = NULL;
- size_t len = 0;
va_list ap;
va_start(ap, fmt);
- len = SDL3_vsnprintf(&ch, 1, fmt, ap);
+ SDL3_SetErrorV(fmt, ap);
va_end(ap);
- str = (char *) SDL3_malloc(len + 1);
- if (str) {
- va_start(ap, fmt);
- SDL3_vsnprintf(str, len + 1, fmt, ap);
- va_end(ap);
- SDL3_SetError("%s", str);
- SDL3_free(str);
- }
return -1;
}
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index b8070ec..d2af0e8 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -47,6 +47,7 @@
#endif
SDL3_SYM_VARARGS(bool,SetError,(SDL_PRINTF_FORMAT_STRING const char *a, ...))
+SDL3_SYM(bool,SetErrorV,(SDL_PRINTF_FORMAT_STRING const char *a, va_list b),(a,b),return);
SDL3_SYM_VARARGS(void,Log,(SDL_PRINTF_FORMAT_STRING const char *a, ...))
SDL3_SYM_VARARGS(void,LogVerbose,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...))
SDL3_SYM_VARARGS(void,LogDebug,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...))