Skip to content

Commit

Permalink
make sure SDL_vsnprintf() nul terminates if it is using _vsnprintf
Browse files Browse the repository at this point in the history
(bug #3769: backported commit 5e1341f8c467 for windows and watcom.)
  • Loading branch information
sezero committed Jul 1, 2018
1 parent 9b096d4 commit ad155c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/SDL_stdinc.h
Expand Up @@ -575,13 +575,13 @@ extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2,
extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
#endif

#ifdef HAVE_SNPRINTF
#if defined(HAVE_SNPRINTF) && !(defined(__WATCOMC__) || defined(_WIN32))
#define SDL_snprintf snprintf
#else
extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
#endif

#ifdef HAVE_VSNPRINTF
#if defined(HAVE_VSNPRINTF) && !(defined(__WATCOMC__) || defined(_WIN32))
#define SDL_vsnprintf vsnprintf
#else
extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
Expand Down
12 changes: 10 additions & 2 deletions src/stdlib/SDL_string.c
Expand Up @@ -1013,7 +1013,7 @@ int SDL_sscanf(const char *text, const char *fmt, ...)
}
#endif

#ifndef HAVE_SNPRINTF
#if defined(__WATCOMC__) || defined(_WIN32) || !defined(HAVE_SNPRINTF)
int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
{
va_list ap;
Expand All @@ -1027,7 +1027,15 @@ int SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
}
#endif

#ifndef HAVE_VSNPRINTF
#if (defined(__WATCOMC__) || defined(_WIN32)) && defined(HAVE_LIBC)
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
{
int retval = _vsnprintf(text, maxlen, fmt, ap);
if (maxlen > 0) text[maxlen-1] = '\0';
if (retval < 0) retval = (int) maxlen;
return retval;
}
#elif !defined(HAVE_VSNPRINTF)
static size_t SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
{
char num[130];
Expand Down

0 comments on commit ad155c7

Please sign in to comment.