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

**URL:** <https://discourse.libsdl.org/t/sdl-fix-sigsev-in-sdl-error-after-removing-the-limit-on-the-size-of-the-sdl-error-message-see-5795/37453>\
**Category:** SDL Commits\
**Created:** [June 28, 2022, 7:48am UTC](https://discourse.libsdl.org/t/sdl-fix-sigsev-in-sdl-error-after-removing-the-limit-on-the-size-of-the-sdl-error-message-see-5795/37453 "2022-06-28T07:48:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [June 28, 2022, 7:48am UTC](https://discourse.libsdl.org/t/sdl-fix-sigsev-in-sdl-error-after-removing-the-limit-on-the-size-of-the-sdl-error-message-see-5795/37453/1 "2022-06-28T07:48:02Z")

</div>

> <https://github.com/libsdl-org/SDL/commit/d4e6047e3cc73698a0d6b3b4a2ce7b9b5e025b2f>

```diff
From d4e6047e3cc73698a0d6b3b4a2ce7b9b5e025b2f Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Tue, 28 Jun 2022 09:46:12 +0200
Subject: [PATCH] Fix SIGSEV in SDL_error (After removing the limit on the size
 of the SDL error message) (see #5795)

---
 src/SDL_error.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/SDL_error.c b/src/SDL_error.c
index e3501e67b5a..1ca460a6903 100644
--- a/src/SDL_error.c
+++ b/src/SDL_error.c
@@ -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 */

```
