make sure SDL_vsnprintf() nul terminates if it is using _vsnprintf SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Sun, 01 Jul 2018 09:50:47 +0300
branchSDL-1.2
changeset 12050f68904a749c9
parent 12049 69d8281bdd66
child 12051 cd446a3cfd07
make sure SDL_vsnprintf() nul terminates if it is using _vsnprintf

(bug #3769: backported commit 5e1341f8c467 for windows and watcom.)
include/SDL_stdinc.h
src/stdlib/SDL_string.c
     1.1 --- a/include/SDL_stdinc.h	Sun Jul 01 09:27:03 2018 +0300
     1.2 +++ b/include/SDL_stdinc.h	Sun Jul 01 09:50:47 2018 +0300
     1.3 @@ -575,13 +575,13 @@
     1.4  extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
     1.5  #endif
     1.6  
     1.7 -#ifdef HAVE_SNPRINTF
     1.8 +#if defined(HAVE_SNPRINTF) && !(defined(__WATCOMC__) || defined(_WIN32))
     1.9  #define SDL_snprintf    snprintf
    1.10  #else
    1.11  extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
    1.12  #endif
    1.13  
    1.14 -#ifdef HAVE_VSNPRINTF
    1.15 +#if defined(HAVE_VSNPRINTF) && !(defined(__WATCOMC__) || defined(_WIN32))
    1.16  #define SDL_vsnprintf   vsnprintf
    1.17  #else
    1.18  extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
     2.1 --- a/src/stdlib/SDL_string.c	Sun Jul 01 09:27:03 2018 +0300
     2.2 +++ b/src/stdlib/SDL_string.c	Sun Jul 01 09:50:47 2018 +0300
     2.3 @@ -1013,7 +1013,7 @@
     2.4  }
     2.5  #endif
     2.6  
     2.7 -#ifndef HAVE_SNPRINTF
     2.8 +#if defined(__WATCOMC__) || defined(_WIN32) || !defined(HAVE_SNPRINTF)
     2.9  int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
    2.10  {
    2.11      va_list ap;
    2.12 @@ -1027,7 +1027,15 @@
    2.13  }
    2.14  #endif
    2.15  
    2.16 -#ifndef HAVE_VSNPRINTF
    2.17 +#if (defined(__WATCOMC__) || defined(_WIN32)) && defined(HAVE_LIBC)
    2.18 +int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
    2.19 +{
    2.20 +    int retval = _vsnprintf(text, maxlen, fmt, ap);
    2.21 +    if (maxlen > 0) text[maxlen-1] = '\0';
    2.22 +    if (retval < 0) retval = (int) maxlen;
    2.23 +    return retval;
    2.24 +}
    2.25 +#elif !defined(HAVE_VSNPRINTF)
    2.26  static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
    2.27  {
    2.28      char num[130];