Added annotations to help code analysis tools
authorSam Lantinga <slouken@libsdl.org>
Wed, 04 Jun 2014 10:56:56 -0700
changeset 88200e935d5b193a
parent 8819 728adb496260
child 8821 9f2d28d8c136
Added annotations to help code analysis tools

CR: Bruce Dawson
include/SDL_error.h
include/SDL_log.h
include/SDL_stdinc.h
include/SDL_test_assert.h
include/SDL_test_log.h
src/SDL_error.c
src/SDL_log.c
src/audio/SDL_wave.c
src/dynapi/SDL_dynapi.c
src/dynapi/SDL_dynapi_procs.h
src/joystick/windows/SDL_dxjoystick.c
src/power/SDL_power.c
src/stdlib/SDL_string.c
src/test/SDL_test_assert.c
src/test/SDL_test_log.c
src/video/SDL_video.c
     1.1 --- a/include/SDL_error.h	Wed Jun 04 10:56:43 2014 -0700
     1.2 +++ b/include/SDL_error.h	Wed Jun 04 10:56:56 2014 -0700
     1.3 @@ -38,7 +38,7 @@
     1.4  
     1.5  /* Public functions */
     1.6  /* SDL_SetError() unconditionally returns -1. */
     1.7 -extern DECLSPEC int SDLCALL SDL_SetError(const char *fmt, ...);
     1.8 +extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
     1.9  extern DECLSPEC const char *SDLCALL SDL_GetError(void);
    1.10  extern DECLSPEC void SDLCALL SDL_ClearError(void);
    1.11  
     2.1 --- a/include/SDL_log.h	Wed Jun 04 10:56:43 2014 -0700
     2.2 +++ b/include/SDL_log.h	Wed Jun 04 10:56:56 2014 -0700
     2.3 @@ -137,44 +137,44 @@
     2.4  /**
     2.5   *  \brief Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO
     2.6   */
     2.7 -extern DECLSPEC void SDLCALL SDL_Log(const char *fmt, ...);
     2.8 +extern DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
     2.9  
    2.10  /**
    2.11   *  \brief Log a message with SDL_LOG_PRIORITY_VERBOSE
    2.12   */
    2.13 -extern DECLSPEC void SDLCALL SDL_LogVerbose(int category, const char *fmt, ...);
    2.14 +extern DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
    2.15  
    2.16  /**
    2.17   *  \brief Log a message with SDL_LOG_PRIORITY_DEBUG
    2.18   */
    2.19 -extern DECLSPEC void SDLCALL SDL_LogDebug(int category, const char *fmt, ...);
    2.20 +extern DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
    2.21  
    2.22  /**
    2.23   *  \brief Log a message with SDL_LOG_PRIORITY_INFO
    2.24   */
    2.25 -extern DECLSPEC void SDLCALL SDL_LogInfo(int category, const char *fmt, ...);
    2.26 +extern DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
    2.27  
    2.28  /**
    2.29   *  \brief Log a message with SDL_LOG_PRIORITY_WARN
    2.30   */
    2.31 -extern DECLSPEC void SDLCALL SDL_LogWarn(int category, const char *fmt, ...);
    2.32 +extern DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
    2.33  
    2.34  /**
    2.35   *  \brief Log a message with SDL_LOG_PRIORITY_ERROR
    2.36   */
    2.37 -extern DECLSPEC void SDLCALL SDL_LogError(int category, const char *fmt, ...);
    2.38 +extern DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
    2.39  
    2.40  /**
    2.41   *  \brief Log a message with SDL_LOG_PRIORITY_CRITICAL
    2.42   */
    2.43 -extern DECLSPEC void SDLCALL SDL_LogCritical(int category, const char *fmt, ...);
    2.44 +extern DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
    2.45  
    2.46  /**
    2.47   *  \brief Log a message with the specified category and priority.
    2.48   */
    2.49  extern DECLSPEC void SDLCALL SDL_LogMessage(int category,
    2.50                                              SDL_LogPriority priority,
    2.51 -                                            const char *fmt, ...);
    2.52 +                                            SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
    2.53  
    2.54  /**
    2.55   *  \brief Log a message with the specified category and priority.
     3.1 --- a/include/SDL_stdinc.h	Wed Jun 04 10:56:43 2014 -0700
     3.2 +++ b/include/SDL_stdinc.h	Wed Jun 04 10:56:56 2014 -0700
     3.3 @@ -166,6 +166,50 @@
     3.4  /* @} *//* Basic data types */
     3.5  
     3.6  
     3.7 +/* Annotations to help code analysis tools */
     3.8 +#ifdef SDL_DISABLE_ANALYZE_MACROS
     3.9 +#define SDL_IN_BYTECAP(x)
    3.10 +#define SDL_INOUT_Z_CAP(x)
    3.11 +#define SDL_OUT_Z_CAP(x)
    3.12 +#define SDL_OUT_CAP(x)
    3.13 +#define SDL_OUT_BYTECAP(x)
    3.14 +#define SDL_OUT_Z_BYTECAP(x)
    3.15 +#define SDL_PRINTF_FORMAT_STRING
    3.16 +#define SDL_SCANF_FORMAT_STRING
    3.17 +#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
    3.18 +#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
    3.19 +#else
    3.20 +#if _MSC_VER >= 1600 /* VS 2010 and above */
    3.21 +#include <sal.h>
    3.22 +
    3.23 +#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
    3.24 +#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
    3.25 +#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
    3.26 +#define SDL_OUT_CAP(x) _Out_cap_(x)
    3.27 +#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
    3.28 +#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
    3.29 +
    3.30 +#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
    3.31 +#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
    3.32 +#else
    3.33 +#define SDL_IN_BYTECAP(x)
    3.34 +#define SDL_INOUT_Z_CAP(x)
    3.35 +#define SDL_OUT_Z_CAP(x)
    3.36 +#define SDL_OUT_CAP(x)
    3.37 +#define SDL_OUT_BYTECAP(x)
    3.38 +#define SDL_OUT_Z_BYTECAP(x)
    3.39 +#define SDL_PRINTF_FORMAT_STRING
    3.40 +#define SDL_SCANF_FORMAT_STRING
    3.41 +#endif
    3.42 +#if defined(__GNUC__)
    3.43 +#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
    3.44 +#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
    3.45 +#else
    3.46 +#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
    3.47 +#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
    3.48 +#endif
    3.49 +#endif /* SDL_DISABLE_ANALYSE_MACROS */
    3.50 +
    3.51  #define SDL_COMPILE_TIME_ASSERT(name, x)               \
    3.52         typedef int SDL_dummy_ ## name[(x) * 2 - 1]
    3.53  /** \cond */
    3.54 @@ -259,7 +303,7 @@
    3.55  extern DECLSPEC int SDLCALL SDL_toupper(int x);
    3.56  extern DECLSPEC int SDLCALL SDL_tolower(int x);
    3.57  
    3.58 -extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
    3.59 +extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
    3.60  
    3.61  #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
    3.62  #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
    3.63 @@ -294,24 +338,24 @@
    3.64  }
    3.65  
    3.66  
    3.67 -extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
    3.68 +extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
    3.69  
    3.70 -SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
    3.71 +SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
    3.72  {
    3.73      return SDL_memcpy(dst, src, dwords * 4);
    3.74  }
    3.75  
    3.76 -extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
    3.77 +extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
    3.78  extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
    3.79  
    3.80  extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
    3.81 -extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
    3.82 -extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
    3.83 +extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
    3.84 +extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
    3.85  
    3.86  extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
    3.87 -extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
    3.88 -extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
    3.89 -extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
    3.90 +extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
    3.91 +extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
    3.92 +extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
    3.93  extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
    3.94  extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
    3.95  extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
    3.96 @@ -340,10 +384,10 @@
    3.97  extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
    3.98  extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
    3.99  
   3.100 -extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
   3.101 +extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
   3.102  extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
   3.103 -extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
   3.104 -extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
   3.105 +extern DECLSPEC int SDLCALL SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... ) SDL_PRINTF_VARARG_FUNC(3);
   3.106 +extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);
   3.107  
   3.108  #ifndef HAVE_M_PI
   3.109  #ifndef M_PI
     4.1 --- a/include/SDL_test_assert.h	Wed Jun 04 10:56:43 2014 -0700
     4.2 +++ b/include/SDL_test_assert.h	Wed Jun 04 10:56:56 2014 -0700
     4.3 @@ -58,7 +58,7 @@
     4.4   * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
     4.5   * \param assertDescription Message to log with the assert describing it.
     4.6   */
     4.7 -void SDLTest_Assert(int assertCondition, const char *assertDescription, ...);
     4.8 +void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
     4.9  
    4.10  /**
    4.11   * \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
    4.12 @@ -68,14 +68,14 @@
    4.13   *
    4.14   * \returns Returns the assertCondition so it can be used to externally to break execution flow if desired.
    4.15   */
    4.16 -int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...);
    4.17 +int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
    4.18  
    4.19  /**
    4.20   * \brief Explicitely pass without checking an assertion condition. Updates assertion counter.
    4.21   *
    4.22   * \param assertDescription Message to log with the assert describing it.
    4.23   */
    4.24 -void SDLTest_AssertPass(const char *assertDescription, ...);
    4.25 +void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(1);
    4.26  
    4.27  /**
    4.28   * \brief Resets the assert summary counters to zero.
     5.1 --- a/include/SDL_test_log.h	Wed Jun 04 10:56:43 2014 -0700
     5.2 +++ b/include/SDL_test_log.h	Wed Jun 04 10:56:56 2014 -0700
     5.3 @@ -47,14 +47,14 @@
     5.4   *
     5.5   * \param fmt Message to be logged
     5.6   */
     5.7 -void SDLTest_Log(const char *fmt, ...);
     5.8 +void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
     5.9  
    5.10  /**
    5.11   * \brief Prints given message with a timestamp in the TEST category and the ERROR priority.
    5.12   *
    5.13   * \param fmt Message to be logged
    5.14   */
    5.15 -void SDLTest_LogError(const char *fmt, ...);
    5.16 +void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
    5.17  
    5.18  /* Ends C function definitions when using C++ */
    5.19  #ifdef __cplusplus
     6.1 --- a/src/SDL_error.c	Wed Jun 04 10:56:43 2014 -0700
     6.2 +++ b/src/SDL_error.c	Wed Jun 04 10:56:56 2014 -0700
     6.3 @@ -50,7 +50,7 @@
     6.4  /* Public functions */
     6.5  
     6.6  int
     6.7 -SDL_SetError(const char *fmt, ...)
     6.8 +SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
     6.9  {
    6.10      va_list ap;
    6.11      SDL_error *error;
     7.1 --- a/src/SDL_log.c	Wed Jun 04 10:56:43 2014 -0700
     7.2 +++ b/src/SDL_log.c	Wed Jun 04 10:56:56 2014 -0700
     7.3 @@ -26,6 +26,7 @@
     7.4  
     7.5  /* Simple log messages in SDL */
     7.6  
     7.7 +#include "SDL_error.h"
     7.8  #include "SDL_log.h"
     7.9  
    7.10  #if HAVE_STDIO_H
    7.11 @@ -41,9 +42,6 @@
    7.12  #define DEFAULT_APPLICATION_PRIORITY    SDL_LOG_PRIORITY_INFO
    7.13  #define DEFAULT_TEST_PRIORITY           SDL_LOG_PRIORITY_VERBOSE
    7.14  
    7.15 -/* Forward definition of error function */
    7.16 -extern int SDL_SetError(const char *fmt, ...);
    7.17 -
    7.18  typedef struct SDL_LogLevel
    7.19  {
    7.20      int category;
    7.21 @@ -172,7 +170,7 @@
    7.22  }
    7.23  
    7.24  void
    7.25 -SDL_Log(const char *fmt, ...)
    7.26 +SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    7.27  {
    7.28      va_list ap;
    7.29  
    7.30 @@ -182,7 +180,7 @@
    7.31  }
    7.32  
    7.33  void
    7.34 -SDL_LogVerbose(int category, const char *fmt, ...)
    7.35 +SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    7.36  {
    7.37      va_list ap;
    7.38  
    7.39 @@ -192,7 +190,7 @@
    7.40  }
    7.41  
    7.42  void
    7.43 -SDL_LogDebug(int category, const char *fmt, ...)
    7.44 +SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    7.45  {
    7.46      va_list ap;
    7.47  
    7.48 @@ -202,7 +200,7 @@
    7.49  }
    7.50  
    7.51  void
    7.52 -SDL_LogInfo(int category, const char *fmt, ...)
    7.53 +SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    7.54  {
    7.55      va_list ap;
    7.56  
    7.57 @@ -212,7 +210,7 @@
    7.58  }
    7.59  
    7.60  void
    7.61 -SDL_LogWarn(int category, const char *fmt, ...)
    7.62 +SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    7.63  {
    7.64      va_list ap;
    7.65  
    7.66 @@ -222,7 +220,7 @@
    7.67  }
    7.68  
    7.69  void
    7.70 -SDL_LogError(int category, const char *fmt, ...)
    7.71 +SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    7.72  {
    7.73      va_list ap;
    7.74  
    7.75 @@ -232,7 +230,7 @@
    7.76  }
    7.77  
    7.78  void
    7.79 -SDL_LogCritical(int category, const char *fmt, ...)
    7.80 +SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    7.81  {
    7.82      va_list ap;
    7.83  
    7.84 @@ -242,7 +240,7 @@
    7.85  }
    7.86  
    7.87  void
    7.88 -SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt, ...)
    7.89 +SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    7.90  {
    7.91      va_list ap;
    7.92  
     8.1 --- a/src/audio/SDL_wave.c	Wed Jun 04 10:56:43 2014 -0700
     8.2 +++ b/src/audio/SDL_wave.c	Wed Jun 04 10:56:56 2014 -0700
     8.3 @@ -493,8 +493,7 @@
     8.4          IMA_ADPCM_encoded = 1;
     8.5          break;
     8.6      case MP3_CODE:
     8.7 -        SDL_SetError("MPEG Layer 3 data not supported",
     8.8 -                     SDL_SwapLE16(format->encoding));
     8.9 +        SDL_SetError("MPEG Layer 3 data not supported");
    8.10          was_error = 1;
    8.11          goto done;
    8.12      default:
     9.1 --- a/src/dynapi/SDL_dynapi.c	Wed Jun 04 10:56:43 2014 -0700
     9.2 +++ b/src/dynapi/SDL_dynapi.c	Wed Jun 04 10:56:56 2014 -0700
     9.3 @@ -56,38 +56,38 @@
     9.4  #if DISABLE_JUMP_MAGIC
     9.5  /* Can't use the macro for varargs nonsense. This is atrocious. */
     9.6  #define SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, logname, prio) \
     9.7 -    _static void SDL_Log##logname##name(int category, const char *fmt, ...) { \
     9.8 +    _static void SDL_Log##logname##name(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
     9.9          va_list ap; initcall; va_start(ap, fmt); \
    9.10          jump_table.SDL_LogMessageV(category, SDL_LOG_PRIORITY_##prio, fmt, ap); \
    9.11          va_end(ap); \
    9.12      }
    9.13  
    9.14  #define SDL_DYNAPI_VARARGS(_static, name, initcall) \
    9.15 -    _static int SDL_SetError##name(const char *fmt, ...) { \
    9.16 +    _static int SDL_SetError##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
    9.17          char buf[512]; /* !!! FIXME: dynamic allocation */ \
    9.18          va_list ap; initcall; va_start(ap, fmt); \
    9.19          jump_table.SDL_vsnprintf(buf, sizeof (buf), fmt, ap); \
    9.20          va_end(ap); \
    9.21          return jump_table.SDL_SetError("%s", buf); \
    9.22      } \
    9.23 -    _static int SDL_sscanf##name(const char *buf, const char *fmt, ...) { \
    9.24 +    _static int SDL_sscanf##name(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...) { \
    9.25          int retval; va_list ap; initcall; va_start(ap, fmt); \
    9.26          retval = jump_table.SDL_vsscanf(buf, fmt, ap); \
    9.27          va_end(ap); \
    9.28          return retval; \
    9.29      } \
    9.30 -    _static int SDL_snprintf##name(char *buf, size_t buflen, const char *fmt, ...) { \
    9.31 +    _static int SDL_snprintf##name(SDL_OUT_Z_CAP(maxlen) char *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
    9.32          int retval; va_list ap; initcall; va_start(ap, fmt); \
    9.33 -        retval = jump_table.SDL_vsnprintf(buf, buflen, fmt, ap); \
    9.34 +        retval = jump_table.SDL_vsnprintf(buf, maxlen, fmt, ap); \
    9.35          va_end(ap); \
    9.36          return retval; \
    9.37      } \
    9.38 -    _static void SDL_Log##name(const char *fmt, ...) { \
    9.39 +    _static void SDL_Log##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
    9.40          va_list ap; initcall; va_start(ap, fmt); \
    9.41          jump_table.SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); \
    9.42          va_end(ap); \
    9.43      } \
    9.44 -    _static void SDL_LogMessage##name(int category, SDL_LogPriority priority, const char *fmt, ...) { \
    9.45 +    _static void SDL_LogMessage##name(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
    9.46          va_list ap; initcall; va_start(ap, fmt); \
    9.47          jump_table.SDL_LogMessageV(category, priority, fmt, ap); \
    9.48          va_end(ap); \
    10.1 --- a/src/dynapi/SDL_dynapi_procs.h	Wed Jun 04 10:56:43 2014 -0700
    10.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Wed Jun 04 10:56:56 2014 -0700
    10.3 @@ -31,17 +31,17 @@
    10.4  
    10.5  /* direct jump magic can use these, the rest needs special code. */
    10.6  #if !SDL_DYNAPI_PROC_NO_VARARGS
    10.7 -SDL_DYNAPI_PROC(int,SDL_SetError,(const char *a, ...),(a),return)
    10.8 -SDL_DYNAPI_PROC(void,SDL_Log,(const char *a, ...),(a),)
    10.9 -SDL_DYNAPI_PROC(void,SDL_LogVerbose,(int a, const char *b, ...),(a,b),)
   10.10 -SDL_DYNAPI_PROC(void,SDL_LogDebug,(int a, const char *b, ...),(a,b),)
   10.11 -SDL_DYNAPI_PROC(void,SDL_LogInfo,(int a, const char *b, ...),(a,b),)
   10.12 -SDL_DYNAPI_PROC(void,SDL_LogWarn,(int a, const char *b, ...),(a,b),)
   10.13 -SDL_DYNAPI_PROC(void,SDL_LogError,(int a, const char *b, ...),(a,b),)
   10.14 -SDL_DYNAPI_PROC(void,SDL_LogCritical,(int a, const char *b, ...),(a,b),)
   10.15 -SDL_DYNAPI_PROC(void,SDL_LogMessage,(int a, SDL_LogPriority b, const char *c, ...),(a,b,c),)
   10.16 -SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, const char *b, ...),(a,b),return)
   10.17 -SDL_DYNAPI_PROC(int,SDL_snprintf,(char *a, size_t b, const char *c, ...),(a,b,c),return)
   10.18 +SDL_DYNAPI_PROC(int,SDL_SetError,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),return)
   10.19 +SDL_DYNAPI_PROC(void,SDL_Log,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),)
   10.20 +SDL_DYNAPI_PROC(void,SDL_LogVerbose,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
   10.21 +SDL_DYNAPI_PROC(void,SDL_LogDebug,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
   10.22 +SDL_DYNAPI_PROC(void,SDL_LogInfo,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
   10.23 +SDL_DYNAPI_PROC(void,SDL_LogWarn,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
   10.24 +SDL_DYNAPI_PROC(void,SDL_LogError,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
   10.25 +SDL_DYNAPI_PROC(void,SDL_LogCritical,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
   10.26 +SDL_DYNAPI_PROC(void,SDL_LogMessage,(int a, SDL_LogPriority b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),)
   10.27 +SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, SDL_SCANF_FORMAT_STRING const char *b, ...),(a,b),return)
   10.28 +SDL_DYNAPI_PROC(int,SDL_snprintf,(SDL_OUT_Z_CAP(b) char *a, size_t b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),return)
   10.29  #endif
   10.30  
   10.31  #ifdef SDL_CreateThread
   10.32 @@ -418,17 +418,17 @@
   10.33  SDL_DYNAPI_PROC(int,SDL_isspace,(int a),(a),return)
   10.34  SDL_DYNAPI_PROC(int,SDL_toupper,(int a),(a),return)
   10.35  SDL_DYNAPI_PROC(int,SDL_tolower,(int a),(a),return)
   10.36 -SDL_DYNAPI_PROC(void*,SDL_memset,(void *a, int b, size_t c),(a,b,c),return)
   10.37 -SDL_DYNAPI_PROC(void*,SDL_memcpy,(void *a, const void *b, size_t c),(a,b,c),return)
   10.38 -SDL_DYNAPI_PROC(void*,SDL_memmove,(void *a, const void *b, size_t c),(a,b,c),return)
   10.39 +SDL_DYNAPI_PROC(void*,SDL_memset,(SDL_OUT_BYTECAP(c) void *a, int b, size_t c),(a,b,c),return)
   10.40 +SDL_DYNAPI_PROC(void*,SDL_memcpy,(SDL_OUT_BYTECAP(c) void *a, SDL_IN_BYTECAP(c) const void *b, size_t c),(a,b,c),return)
   10.41 +SDL_DYNAPI_PROC(void*,SDL_memmove,(SDL_OUT_BYTECAP(c) void *a, SDL_IN_BYTECAP(c) const void *b, size_t c),(a,b,c),return)
   10.42  SDL_DYNAPI_PROC(int,SDL_memcmp,(const void *a, const void *b, size_t c),(a,b,c),return)
   10.43  SDL_DYNAPI_PROC(size_t,SDL_wcslen,(const wchar_t *a),(a),return)
   10.44 -SDL_DYNAPI_PROC(size_t,SDL_wcslcpy,(wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
   10.45 -SDL_DYNAPI_PROC(size_t,SDL_wcslcat,(wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
   10.46 +SDL_DYNAPI_PROC(size_t,SDL_wcslcpy,(SDL_OUT_Z_CAP(c) wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
   10.47 +SDL_DYNAPI_PROC(size_t,SDL_wcslcat,(SDL_INOUT_Z_CAP(c) wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
   10.48  SDL_DYNAPI_PROC(size_t,SDL_strlen,(const char *a),(a),return)
   10.49 -SDL_DYNAPI_PROC(size_t,SDL_strlcpy,(char *a, const char *b, size_t c),(a,b,c),return)
   10.50 -SDL_DYNAPI_PROC(size_t,SDL_utf8strlcpy,(char *a, const char *b, size_t c),(a,b,c),return)
   10.51 -SDL_DYNAPI_PROC(size_t,SDL_strlcat,(char *a, const char *b, size_t c),(a,b,c),return)
   10.52 +SDL_DYNAPI_PROC(size_t,SDL_strlcpy,(SDL_OUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
   10.53 +SDL_DYNAPI_PROC(size_t,SDL_utf8strlcpy,(SDL_OUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
   10.54 +SDL_DYNAPI_PROC(size_t,SDL_strlcat,(SDL_INOUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
   10.55  SDL_DYNAPI_PROC(char*,SDL_strdup,(const char *a),(a),return)
   10.56  SDL_DYNAPI_PROC(char*,SDL_strrev,(char *a),(a),return)
   10.57  SDL_DYNAPI_PROC(char*,SDL_strupr,(char *a),(a),return)
   10.58 @@ -453,7 +453,7 @@
   10.59  SDL_DYNAPI_PROC(int,SDL_strncmp,(const char *a, const char *b, size_t c),(a,b,c),return)
   10.60  SDL_DYNAPI_PROC(int,SDL_strcasecmp,(const char *a, const char *b),(a,b),return)
   10.61  SDL_DYNAPI_PROC(int,SDL_strncasecmp,(const char *a, const char *b, size_t c),(a,b,c),return)
   10.62 -SDL_DYNAPI_PROC(int,SDL_vsnprintf,(char *a, size_t b, const char *c, va_list d),(a,b,c,d),return)
   10.63 +SDL_DYNAPI_PROC(int,SDL_vsnprintf,(SDL_OUT_Z_CAP(b) char *a, size_t b, const char *c, va_list d),(a,b,c,d),return)
   10.64  SDL_DYNAPI_PROC(double,SDL_acos,(double a),(a),return)
   10.65  SDL_DYNAPI_PROC(double,SDL_asin,(double a),(a),return)
   10.66  SDL_DYNAPI_PROC(double,SDL_atan,(double a),(a),return)
    11.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Wed Jun 04 10:56:43 2014 -0700
    11.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Wed Jun 04 10:56:56 2014 -0700
    11.3 @@ -45,6 +45,7 @@
    11.4  #if !SDL_EVENTS_DISABLED
    11.5  #include "../../events/SDL_events_c.h"
    11.6  #endif
    11.7 +#include "../../core/windows/SDL_windows.h"
    11.8  
    11.9  #define INITGUID /* Only set here, if set twice will cause mingw32 to break. */
   11.10  #include "SDL_dxjoystick_c.h"
   11.11 @@ -499,13 +500,13 @@
   11.12  
   11.13      if (!RegisterClassEx (&wincl))
   11.14      {
   11.15 -        return SDL_SetError("Failed to create register class for joystick autodetect.", GetLastError());
   11.16 +		return WIN_SetError( "Failed to create register class for joystick autodetect");
   11.17      }
   11.18  
   11.19      messageWindow = (HWND)CreateWindowEx( 0,  L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL );
   11.20      if ( !messageWindow )
   11.21      {
   11.22 -        return SDL_SetError("Failed to create message window for joystick autodetect.", GetLastError());
   11.23 +        return WIN_SetError("Failed to create message window for joystick autodetect");
   11.24      }
   11.25  
   11.26      SDL_zero(dbh);
   11.27 @@ -517,7 +518,7 @@
   11.28      hNotify = RegisterDeviceNotification( messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE );
   11.29      if ( !hNotify )
   11.30      {
   11.31 -        return SDL_SetError("Failed to create notify device for joystick autodetect.", GetLastError());
   11.32 +		return WIN_SetError( "Failed to create notify device for joystick autodetect");
   11.33      }
   11.34  
   11.35      SDL_LockMutex( s_mutexJoyStickEnum );
    12.1 --- a/src/power/SDL_power.c	Wed Jun 04 10:56:43 2014 -0700
    12.2 +++ b/src/power/SDL_power.c	Wed Jun 04 10:56:56 2014 -0700
    12.3 @@ -93,7 +93,7 @@
    12.4  {
    12.5      const int total = sizeof(implementations) / sizeof(implementations[0]);
    12.6      int _seconds, _percent;
    12.7 -    SDL_PowerState retval;
    12.8 +    SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
    12.9      int i;
   12.10  
   12.11      /* Make these never NULL for platform-specific implementations. */
   12.12 @@ -106,7 +106,7 @@
   12.13      }
   12.14  
   12.15      for (i = 0; i < total; i++) {
   12.16 -        if (implementations[i] (&retval, seconds, percent)) {
   12.17 +        if (implementations[i](&retval, seconds, percent)) {
   12.18              return retval;
   12.19          }
   12.20      }
    13.1 --- a/src/stdlib/SDL_string.c	Wed Jun 04 10:56:43 2014 -0700
    13.2 +++ b/src/stdlib/SDL_string.c	Wed Jun 04 10:56:56 2014 -0700
    13.3 @@ -258,7 +258,7 @@
    13.4  #endif
    13.5  
    13.6  void *
    13.7 -SDL_memset(void *dst, int c, size_t len)
    13.8 +SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
    13.9  {
   13.10  #if defined(HAVE_MEMSET)
   13.11      return memset(dst, c, len);
   13.12 @@ -302,7 +302,7 @@
   13.13  }
   13.14  
   13.15  void *
   13.16 -SDL_memcpy(void *dst, const void *src, size_t len)
   13.17 +SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
   13.18  {
   13.19  #ifdef __GNUC__
   13.20      /* Presumably this is well tuned for speed.
   13.21 @@ -355,7 +355,7 @@
   13.22  }
   13.23  
   13.24  void *
   13.25 -SDL_memmove(void *dst, const void *src, size_t len)
   13.26 +SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
   13.27  {
   13.28  #if defined(HAVE_MEMMOVE)
   13.29      return memmove(dst, src, len);
   13.30 @@ -426,7 +426,7 @@
   13.31  }
   13.32  
   13.33  size_t
   13.34 -SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
   13.35 +SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
   13.36  {
   13.37  #if defined(HAVE_WCSLCPY)
   13.38      return wcslcpy(dst, src, maxlen);
   13.39 @@ -442,7 +442,7 @@
   13.40  }
   13.41  
   13.42  size_t
   13.43 -SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
   13.44 +SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
   13.45  {
   13.46  #if defined(HAVE_WCSLCAT)
   13.47      return wcslcat(dst, src, maxlen);
   13.48 @@ -457,7 +457,7 @@
   13.49  }
   13.50  
   13.51  size_t
   13.52 -SDL_strlcpy(char *dst, const char *src, size_t maxlen)
   13.53 +SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
   13.54  {
   13.55  #if defined(HAVE_STRLCPY)
   13.56      return strlcpy(dst, src, maxlen);
   13.57 @@ -472,7 +472,7 @@
   13.58  #endif /* HAVE_STRLCPY */
   13.59  }
   13.60  
   13.61 -size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes)
   13.62 +size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
   13.63  {
   13.64      size_t src_bytes = SDL_strlen(src);
   13.65      size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
   13.66 @@ -505,7 +505,7 @@
   13.67  }
   13.68  
   13.69  size_t
   13.70 -SDL_strlcat(char *dst, const char *src, size_t maxlen)
   13.71 +SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
   13.72  {
   13.73  #if defined(HAVE_STRLCAT)
   13.74      return strlcat(dst, src, maxlen);
   13.75 @@ -980,7 +980,7 @@
   13.76  }
   13.77  
   13.78  int
   13.79 -SDL_sscanf(const char *text, const char *fmt, ...)
   13.80 +SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
   13.81  {
   13.82      int rc;
   13.83      va_list ap;
   13.84 @@ -1261,7 +1261,7 @@
   13.85  #endif /* HAVE_VSSCANF */
   13.86  
   13.87  int
   13.88 -SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
   13.89 +SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
   13.90  {
   13.91      va_list ap;
   13.92      int retval;
   13.93 @@ -1274,7 +1274,7 @@
   13.94  }
   13.95  
   13.96  #ifdef HAVE_VSNPRINTF
   13.97 -int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
   13.98 +int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
   13.99  {
  13.100      return vsnprintf(text, maxlen, fmt, ap);
  13.101  }
  13.102 @@ -1463,7 +1463,7 @@
  13.103  }
  13.104  
  13.105  int
  13.106 -SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
  13.107 +SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
  13.108  {
  13.109      size_t left = maxlen;
  13.110      char *textstart = text;
    14.1 --- a/src/test/SDL_test_assert.c	Wed Jun 04 10:56:43 2014 -0700
    14.2 +++ b/src/test/SDL_test_assert.c	Wed Jun 04 10:56:56 2014 -0700
    14.3 @@ -44,7 +44,7 @@
    14.4  /*
    14.5   *  Assert that logs and break execution flow on failures (i.e. for harness errors).
    14.6   */
    14.7 -void SDLTest_Assert(int assertCondition, const char *assertDescription, ...)
    14.8 +void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
    14.9  {
   14.10          va_list list;
   14.11      char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
   14.12 @@ -62,7 +62,7 @@
   14.13  /*
   14.14   * Assert that logs but does not break execution flow on failures (i.e. for test cases).
   14.15   */
   14.16 -int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...)
   14.17 +int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
   14.18  {
   14.19      va_list list;
   14.20      char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
   14.21 @@ -91,7 +91,7 @@
   14.22  /*
   14.23   * Explicitly passing Assert that logs (i.e. for test cases).
   14.24   */
   14.25 -void SDLTest_AssertPass(const char *assertDescription, ...)
   14.26 +void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
   14.27  {
   14.28      va_list list;
   14.29      char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    15.1 --- a/src/test/SDL_test_log.c	Wed Jun 04 10:56:43 2014 -0700
    15.2 +++ b/src/test/SDL_test_log.c	Wed Jun 04 10:56:56 2014 -0700
    15.3 @@ -68,7 +68,7 @@
    15.4  /*
    15.5   * Prints given message with a timestamp in the TEST category and INFO priority.
    15.6   */
    15.7 -void SDLTest_Log(const char *fmt, ...)
    15.8 +void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
    15.9  {
   15.10      va_list list;
   15.11      char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
   15.12 @@ -86,7 +86,7 @@
   15.13  /*
   15.14   * Prints given message with a timestamp in the TEST category and the ERROR priority.
   15.15   */
   15.16 -void SDLTest_LogError(const char *fmt, ...)
   15.17 +void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
   15.18  {
   15.19      va_list list;
   15.20      char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    16.1 --- a/src/video/SDL_video.c	Wed Jun 04 10:56:43 2014 -0700
    16.2 +++ b/src/video/SDL_video.c	Wed Jun 04 10:56:56 2014 -0700
    16.3 @@ -1093,7 +1093,9 @@
    16.4  SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
    16.5  {
    16.6      SDL_VideoDisplay *display;
    16.7 -    SDL_Window *other;
    16.8 +	SDL_Window *other;
    16.9 +
   16.10 +	CHECK_WINDOW_MAGIC(window,);
   16.11  
   16.12  #ifdef __MACOSX__
   16.13      if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) {