Fix SIGSEV in SDL_error (After removing the limit on the size of the SDL error message) (see #5795)

This commit is contained in:
Sylvain 2022-06-28 09:46:12 +02:00
parent 7a02dcf3e6
commit d4e6047e3c
No known key found for this signature in database
GPG Key ID: 5F87E02E5BC0939E
1 changed files with 5 additions and 1 deletions

View File

@ -38,16 +38,20 @@ SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
va_start(ap, fmt);
result = SDL_vsnprintf(error->str, error->len, fmt, ap);
va_end(ap);
if (result >= 0 && (size_t)result >= error->len && error->realloc_func) {
size_t len = (size_t)result + 1;
char *str = (char *)error->realloc_func(error->str, len);
if (str) {
error->str = str;
error->len = len;
va_start(ap, fmt);
SDL_vsnprintf(error->str, error->len, fmt, ap);
va_end(ap);
}
}
va_end(ap);
if (SDL_LogGetPriority(SDL_LOG_CATEGORY_ERROR) <= SDL_LOG_PRIORITY_DEBUG) {
/* If we are in debug mode, print out the error message */