From 926d803f83f07152f5ed914ece4b9902f61f64d7 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sun, 29 Oct 2017 14:15:00 +0300 Subject: [PATCH] bug #3739: handle %lu, %li and %ld in SDL_SetError. --- src/SDL_error.c | 26 ++++++++++++++++++++++++++ src/SDL_error_c.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/SDL_error.c b/src/SDL_error.c index 460fffdbd..14761c544 100644 --- a/src/SDL_error.c +++ b/src/SDL_error.c @@ -76,6 +76,16 @@ SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) case 0: /* Malformed format string.. */ --fmt; break; + case 'l': + switch (*fmt++) { + case 0: /* Malformed format string.. */ + --fmt; + break; + case 'i': case 'd': case 'u': + error->args[error->argc++].value_l = va_arg(ap, long); + break; + } + break; case 'c': case 'i': case 'd': @@ -219,6 +229,22 @@ SDL_GetErrorMsg(char *errstr, int maxlen) && spot < (tmp + SDL_arraysize(tmp) - 2)) { *spot++ = *fmt++; } + if (*fmt == 'l') { + *spot++ = *fmt++; + *spot++ = *fmt++; + *spot++ = '\0'; + switch (spot[-2]) { + case 'i': case 'd': case 'u': + len = SDL_snprintf(msg, maxlen, tmp, + error->args[argi++].value_l); + if (len > 0) { + msg += len; + maxlen -= len; + } + break; + } + continue; + } *spot++ = *fmt++; *spot++ = '\0'; switch (spot[-2]) { diff --git a/src/SDL_error_c.h b/src/SDL_error_c.h index 4e2196614..6bb9caaf8 100644 --- a/src/SDL_error_c.h +++ b/src/SDL_error_c.h @@ -51,6 +51,7 @@ typedef struct SDL_error unsigned char value_c; #endif int value_i; + long value_l; double value_f; char buf[ERR_MAX_STRLEN]; } args[ERR_MAX_ARGS];