Removed the limit on the size of the SDL error message

Also added SDL_GetOriginalMemoryFunctions()

Fixes https://github.com/libsdl-org/SDL/issues/5795
This commit is contained in:
Sam Lantinga 2022-06-27 16:59:50 -07:00
parent f25b4b2774
commit cbd0187475
11 changed files with 126 additions and 16 deletions

View file

@ -851,3 +851,4 @@
++'_SDL_utf8strnlen'.'SDL2.dll'.'SDL_utf8strnlen'
# ++'_SDL_GDKGetTaskQueue'.'SDL2.dll'.'SDL_GDKGetTaskQueue'
# ++'_SDL_GDKRunApp'.'SDL2.dll'.'SDL_GDKRunApp'
++'_SDL_GetOriginalMemoryFunctions'.'SDL2.dll'.'SDL_GetOriginalMemoryFunctions'

View file

@ -71,11 +71,25 @@ static void SDL_InitDynamicAPI(void);
#define SDL_DYNAPI_VARARGS(_static, name, initcall) \
_static int SDLCALL SDL_SetError##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
char buf[512]; /* !!! FIXME: dynamic allocation */ \
char buf[128], *str = buf; \
int result; \
va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_vsnprintf(buf, sizeof (buf), fmt, ap); \
result = jump_table.SDL_vsnprintf(buf, sizeof(buf), fmt, 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) { \
result = jump_table.SDL_vsnprintf(str, len, fmt, ap); \
} \
} \
va_end(ap); \
return jump_table.SDL_SetError("%s", buf); \
if (result >= 0) { \
result = jump_table.SDL_SetError("%s", str); \
} \
if (str != buf) { \
jump_table.SDL_free(str); \
} \
return result; \
} \
_static int SDLCALL SDL_sscanf##name(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...) { \
int retval; va_list ap; initcall; va_start(ap, fmt); \

View file

@ -877,3 +877,4 @@
#define SDL_utf8strnlen SDL_utf8strnlen_REAL
#define SDL_GDKGetTaskQueue SDL_GDKGetTaskQueue_REAL
#define SDL_GDKRunApp SDL_GDKRunApp_REAL
#define SDL_GetOriginalMemoryFunctions SDL_GetOriginalMemoryFunctions_REAL

View file

@ -960,3 +960,4 @@ SDL_DYNAPI_PROC(size_t,SDL_utf8strnlen,(const char *a, size_t b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GDKGetTaskQueue,(XTaskQueueHandle *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GDKRunApp,(SDL_main_func a, void *b),(a,b),return)
#endif
SDL_DYNAPI_PROC(void,SDL_GetOriginalMemoryFunctions,(SDL_malloc_func *a, SDL_calloc_func *b, SDL_realloc_func *c, SDL_free_func *d),(a,b,c,d),)