|
@@ -612,15 +612,21 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_S
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// If message truncated, allocate and re-render
|
|
// If message truncated, allocate and re-render
|
|
|
- if (len >= sizeof(stack_buf) && SDL_size_add_check_overflow(len, 1, &len_plus_term)) {
|
|
|
|
|
- // Allocate exactly what we need, including the zero-terminator
|
|
|
|
|
- message = (char *)SDL_malloc(len_plus_term);
|
|
|
|
|
- if (!message) {
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ if (len >= sizeof(stack_buf)) {
|
|
|
|
|
+ if (SDL_size_add_check_overflow(len, 1, &len_plus_term)) {
|
|
|
|
|
+ // Allocate exactly what we need, including the zero-terminator
|
|
|
|
|
+ message = (char *)SDL_malloc(len_plus_term);
|
|
|
|
|
+ if (!message) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ va_copy(aq, ap);
|
|
|
|
|
+ len = SDL_vsnprintf(message, len_plus_term, fmt, aq);
|
|
|
|
|
+ va_end(aq);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Allocation would overflow, use truncated message
|
|
|
|
|
+ message = stack_buf;
|
|
|
|
|
+ len = sizeof(stack_buf);
|
|
|
}
|
|
}
|
|
|
- va_copy(aq, ap);
|
|
|
|
|
- len = SDL_vsnprintf(message, len_plus_term, fmt, aq);
|
|
|
|
|
- va_end(aq);
|
|
|
|
|
} else {
|
|
} else {
|
|
|
message = stack_buf;
|
|
message = stack_buf;
|
|
|
}
|
|
}
|