Added annotations to help code analysis tools

CR: Bruce Dawson
This commit is contained in:
Sam Lantinga 2014-06-04 10:56:56 -07:00
parent 529bcf6293
commit da6d9a9f2a
16 changed files with 134 additions and 90 deletions

View File

@ -38,7 +38,7 @@ extern "C" {
/* Public functions */ /* Public functions */
/* SDL_SetError() unconditionally returns -1. */ /* SDL_SetError() unconditionally returns -1. */
extern DECLSPEC int SDLCALL SDL_SetError(const char *fmt, ...); extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
extern DECLSPEC const char *SDLCALL SDL_GetError(void); extern DECLSPEC const char *SDLCALL SDL_GetError(void);
extern DECLSPEC void SDLCALL SDL_ClearError(void); extern DECLSPEC void SDLCALL SDL_ClearError(void);

View File

@ -137,44 +137,44 @@ extern DECLSPEC void SDLCALL SDL_LogResetPriorities(void);
/** /**
* \brief Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO * \brief Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO
*/ */
extern DECLSPEC void SDLCALL SDL_Log(const char *fmt, ...); extern DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
/** /**
* \brief Log a message with SDL_LOG_PRIORITY_VERBOSE * \brief Log a message with SDL_LOG_PRIORITY_VERBOSE
*/ */
extern DECLSPEC void SDLCALL SDL_LogVerbose(int category, const char *fmt, ...); extern DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
/** /**
* \brief Log a message with SDL_LOG_PRIORITY_DEBUG * \brief Log a message with SDL_LOG_PRIORITY_DEBUG
*/ */
extern DECLSPEC void SDLCALL SDL_LogDebug(int category, const char *fmt, ...); extern DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
/** /**
* \brief Log a message with SDL_LOG_PRIORITY_INFO * \brief Log a message with SDL_LOG_PRIORITY_INFO
*/ */
extern DECLSPEC void SDLCALL SDL_LogInfo(int category, const char *fmt, ...); extern DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
/** /**
* \brief Log a message with SDL_LOG_PRIORITY_WARN * \brief Log a message with SDL_LOG_PRIORITY_WARN
*/ */
extern DECLSPEC void SDLCALL SDL_LogWarn(int category, const char *fmt, ...); extern DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
/** /**
* \brief Log a message with SDL_LOG_PRIORITY_ERROR * \brief Log a message with SDL_LOG_PRIORITY_ERROR
*/ */
extern DECLSPEC void SDLCALL SDL_LogError(int category, const char *fmt, ...); extern DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
/** /**
* \brief Log a message with SDL_LOG_PRIORITY_CRITICAL * \brief Log a message with SDL_LOG_PRIORITY_CRITICAL
*/ */
extern DECLSPEC void SDLCALL SDL_LogCritical(int category, const char *fmt, ...); extern DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
/** /**
* \brief Log a message with the specified category and priority. * \brief Log a message with the specified category and priority.
*/ */
extern DECLSPEC void SDLCALL SDL_LogMessage(int category, extern DECLSPEC void SDLCALL SDL_LogMessage(int category,
SDL_LogPriority priority, SDL_LogPriority priority,
const char *fmt, ...); SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
/** /**
* \brief Log a message with the specified category and priority. * \brief Log a message with the specified category and priority.

View File

@ -166,6 +166,50 @@ typedef uint64_t Uint64;
/* @} *//* Basic data types */ /* @} *//* Basic data types */
/* Annotations to help code analysis tools */
#ifdef SDL_DISABLE_ANALYZE_MACROS
#define SDL_IN_BYTECAP(x)
#define SDL_INOUT_Z_CAP(x)
#define SDL_OUT_Z_CAP(x)
#define SDL_OUT_CAP(x)
#define SDL_OUT_BYTECAP(x)
#define SDL_OUT_Z_BYTECAP(x)
#define SDL_PRINTF_FORMAT_STRING
#define SDL_SCANF_FORMAT_STRING
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
#else
#if _MSC_VER >= 1600 /* VS 2010 and above */
#include <sal.h>
#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
#define SDL_OUT_CAP(x) _Out_cap_(x)
#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
#else
#define SDL_IN_BYTECAP(x)
#define SDL_INOUT_Z_CAP(x)
#define SDL_OUT_Z_CAP(x)
#define SDL_OUT_CAP(x)
#define SDL_OUT_BYTECAP(x)
#define SDL_OUT_Z_BYTECAP(x)
#define SDL_PRINTF_FORMAT_STRING
#define SDL_SCANF_FORMAT_STRING
#endif
#if defined(__GNUC__)
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
#else
#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
#endif
#endif /* SDL_DISABLE_ANALYSE_MACROS */
#define SDL_COMPILE_TIME_ASSERT(name, x) \ #define SDL_COMPILE_TIME_ASSERT(name, x) \
typedef int SDL_dummy_ ## name[(x) * 2 - 1] typedef int SDL_dummy_ ## name[(x) * 2 - 1]
/** \cond */ /** \cond */
@ -259,7 +303,7 @@ extern DECLSPEC int SDLCALL SDL_isspace(int x);
extern DECLSPEC int SDLCALL SDL_toupper(int x); extern DECLSPEC int SDLCALL SDL_toupper(int x);
extern DECLSPEC int SDLCALL SDL_tolower(int x); extern DECLSPEC int SDLCALL SDL_tolower(int x);
extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len); extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x))) #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x))) #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
@ -294,24 +338,24 @@ SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
} }
extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len); extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords) SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
{ {
return SDL_memcpy(dst, src, dwords * 4); return SDL_memcpy(dst, src, dwords * 4);
} }
extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len); extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len); extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr); extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen); extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen); extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str); extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen); extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes); extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen); extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
extern DECLSPEC char *SDLCALL SDL_strdup(const char *str); extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
extern DECLSPEC char *SDLCALL SDL_strrev(char *str); extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
extern DECLSPEC char *SDLCALL SDL_strupr(char *str); extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
@ -340,10 +384,10 @@ extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size
extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2); extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len); extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...); extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap); extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...); 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);
extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap); extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);
#ifndef HAVE_M_PI #ifndef HAVE_M_PI
#ifndef M_PI #ifndef M_PI

View File

@ -58,7 +58,7 @@ extern "C" {
* \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0). * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
* \param assertDescription Message to log with the assert describing it. * \param assertDescription Message to log with the assert describing it.
*/ */
void SDLTest_Assert(int assertCondition, const char *assertDescription, ...); void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
/** /**
* \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters. * \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
@ -68,14 +68,14 @@ void SDLTest_Assert(int assertCondition, const char *assertDescription, ...);
* *
* \returns Returns the assertCondition so it can be used to externally to break execution flow if desired. * \returns Returns the assertCondition so it can be used to externally to break execution flow if desired.
*/ */
int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...); int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
/** /**
* \brief Explicitely pass without checking an assertion condition. Updates assertion counter. * \brief Explicitely pass without checking an assertion condition. Updates assertion counter.
* *
* \param assertDescription Message to log with the assert describing it. * \param assertDescription Message to log with the assert describing it.
*/ */
void SDLTest_AssertPass(const char *assertDescription, ...); void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(1);
/** /**
* \brief Resets the assert summary counters to zero. * \brief Resets the assert summary counters to zero.

View File

@ -47,14 +47,14 @@ extern "C" {
* *
* \param fmt Message to be logged * \param fmt Message to be logged
*/ */
void SDLTest_Log(const char *fmt, ...); void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
/** /**
* \brief Prints given message with a timestamp in the TEST category and the ERROR priority. * \brief Prints given message with a timestamp in the TEST category and the ERROR priority.
* *
* \param fmt Message to be logged * \param fmt Message to be logged
*/ */
void SDLTest_LogError(const char *fmt, ...); void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -50,7 +50,7 @@ SDL_LookupString(const char *key)
/* Public functions */ /* Public functions */
int int
SDL_SetError(const char *fmt, ...) SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
SDL_error *error; SDL_error *error;

View File

@ -26,6 +26,7 @@
/* Simple log messages in SDL */ /* Simple log messages in SDL */
#include "SDL_error.h"
#include "SDL_log.h" #include "SDL_log.h"
#if HAVE_STDIO_H #if HAVE_STDIO_H
@ -41,9 +42,6 @@
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO #define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE #define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
/* Forward definition of error function */
extern int SDL_SetError(const char *fmt, ...);
typedef struct SDL_LogLevel typedef struct SDL_LogLevel
{ {
int category; int category;
@ -172,7 +170,7 @@ SDL_LogResetPriorities(void)
} }
void void
SDL_Log(const char *fmt, ...) SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -182,7 +180,7 @@ SDL_Log(const char *fmt, ...)
} }
void void
SDL_LogVerbose(int category, const char *fmt, ...) SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -192,7 +190,7 @@ SDL_LogVerbose(int category, const char *fmt, ...)
} }
void void
SDL_LogDebug(int category, const char *fmt, ...) SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -202,7 +200,7 @@ SDL_LogDebug(int category, const char *fmt, ...)
} }
void void
SDL_LogInfo(int category, const char *fmt, ...) SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -212,7 +210,7 @@ SDL_LogInfo(int category, const char *fmt, ...)
} }
void void
SDL_LogWarn(int category, const char *fmt, ...) SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -222,7 +220,7 @@ SDL_LogWarn(int category, const char *fmt, ...)
} }
void void
SDL_LogError(int category, const char *fmt, ...) SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -232,7 +230,7 @@ SDL_LogError(int category, const char *fmt, ...)
} }
void void
SDL_LogCritical(int category, const char *fmt, ...) SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -242,7 +240,7 @@ SDL_LogCritical(int category, const char *fmt, ...)
} }
void void
SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt, ...) SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;

View File

@ -493,8 +493,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
IMA_ADPCM_encoded = 1; IMA_ADPCM_encoded = 1;
break; break;
case MP3_CODE: case MP3_CODE:
SDL_SetError("MPEG Layer 3 data not supported", SDL_SetError("MPEG Layer 3 data not supported");
SDL_SwapLE16(format->encoding));
was_error = 1; was_error = 1;
goto done; goto done;
default: default:

View File

@ -56,38 +56,38 @@ static void SDL_InitDynamicAPI(void);
#if DISABLE_JUMP_MAGIC #if DISABLE_JUMP_MAGIC
/* Can't use the macro for varargs nonsense. This is atrocious. */ /* Can't use the macro for varargs nonsense. This is atrocious. */
#define SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, logname, prio) \ #define SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, logname, prio) \
_static void SDL_Log##logname##name(int category, const char *fmt, ...) { \ _static void SDL_Log##logname##name(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
va_list ap; initcall; va_start(ap, fmt); \ va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_LogMessageV(category, SDL_LOG_PRIORITY_##prio, fmt, ap); \ jump_table.SDL_LogMessageV(category, SDL_LOG_PRIORITY_##prio, fmt, ap); \
va_end(ap); \ va_end(ap); \
} }
#define SDL_DYNAPI_VARARGS(_static, name, initcall) \ #define SDL_DYNAPI_VARARGS(_static, name, initcall) \
_static int SDL_SetError##name(const char *fmt, ...) { \ _static int SDL_SetError##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
char buf[512]; /* !!! FIXME: dynamic allocation */ \ char buf[512]; /* !!! FIXME: dynamic allocation */ \
va_list ap; initcall; va_start(ap, fmt); \ va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_vsnprintf(buf, sizeof (buf), fmt, ap); \ jump_table.SDL_vsnprintf(buf, sizeof (buf), fmt, ap); \
va_end(ap); \ va_end(ap); \
return jump_table.SDL_SetError("%s", buf); \ return jump_table.SDL_SetError("%s", buf); \
} \ } \
_static int SDL_sscanf##name(const char *buf, const char *fmt, ...) { \ _static int SDL_sscanf##name(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...) { \
int retval; va_list ap; initcall; va_start(ap, fmt); \ int retval; va_list ap; initcall; va_start(ap, fmt); \
retval = jump_table.SDL_vsscanf(buf, fmt, ap); \ retval = jump_table.SDL_vsscanf(buf, fmt, ap); \
va_end(ap); \ va_end(ap); \
return retval; \ return retval; \
} \ } \
_static int SDL_snprintf##name(char *buf, size_t buflen, const char *fmt, ...) { \ _static int SDL_snprintf##name(SDL_OUT_Z_CAP(maxlen) char *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
int retval; va_list ap; initcall; va_start(ap, fmt); \ int retval; va_list ap; initcall; va_start(ap, fmt); \
retval = jump_table.SDL_vsnprintf(buf, buflen, fmt, ap); \ retval = jump_table.SDL_vsnprintf(buf, maxlen, fmt, ap); \
va_end(ap); \ va_end(ap); \
return retval; \ return retval; \
} \ } \
_static void SDL_Log##name(const char *fmt, ...) { \ _static void SDL_Log##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
va_list ap; initcall; va_start(ap, fmt); \ va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); \ jump_table.SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); \
va_end(ap); \ va_end(ap); \
} \ } \
_static void SDL_LogMessage##name(int category, SDL_LogPriority priority, const char *fmt, ...) { \ _static void SDL_LogMessage##name(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
va_list ap; initcall; va_start(ap, fmt); \ va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_LogMessageV(category, priority, fmt, ap); \ jump_table.SDL_LogMessageV(category, priority, fmt, ap); \
va_end(ap); \ va_end(ap); \

View File

@ -31,17 +31,17 @@
/* direct jump magic can use these, the rest needs special code. */ /* direct jump magic can use these, the rest needs special code. */
#if !SDL_DYNAPI_PROC_NO_VARARGS #if !SDL_DYNAPI_PROC_NO_VARARGS
SDL_DYNAPI_PROC(int,SDL_SetError,(const char *a, ...),(a),return) SDL_DYNAPI_PROC(int,SDL_SetError,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),return)
SDL_DYNAPI_PROC(void,SDL_Log,(const char *a, ...),(a),) SDL_DYNAPI_PROC(void,SDL_Log,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),)
SDL_DYNAPI_PROC(void,SDL_LogVerbose,(int a, const char *b, ...),(a,b),) SDL_DYNAPI_PROC(void,SDL_LogVerbose,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogDebug,(int a, const char *b, ...),(a,b),) SDL_DYNAPI_PROC(void,SDL_LogDebug,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogInfo,(int a, const char *b, ...),(a,b),) SDL_DYNAPI_PROC(void,SDL_LogInfo,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogWarn,(int a, const char *b, ...),(a,b),) SDL_DYNAPI_PROC(void,SDL_LogWarn,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogError,(int a, const char *b, ...),(a,b),) SDL_DYNAPI_PROC(void,SDL_LogError,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogCritical,(int a, const char *b, ...),(a,b),) SDL_DYNAPI_PROC(void,SDL_LogCritical,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogMessage,(int a, SDL_LogPriority b, const char *c, ...),(a,b,c),) SDL_DYNAPI_PROC(void,SDL_LogMessage,(int a, SDL_LogPriority b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),)
SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, const char *b, ...),(a,b),return) SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, SDL_SCANF_FORMAT_STRING const char *b, ...),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_snprintf,(char *a, size_t b, const char *c, ...),(a,b,c),return) 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)
#endif #endif
#ifdef SDL_CreateThread #ifdef SDL_CreateThread
@ -418,17 +418,17 @@ SDL_DYNAPI_PROC(int,SDL_isdigit,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_isspace,(int a),(a),return) SDL_DYNAPI_PROC(int,SDL_isspace,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_toupper,(int a),(a),return) SDL_DYNAPI_PROC(int,SDL_toupper,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_tolower,(int a),(a),return) SDL_DYNAPI_PROC(int,SDL_tolower,(int a),(a),return)
SDL_DYNAPI_PROC(void*,SDL_memset,(void *a, int b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(void*,SDL_memset,(SDL_OUT_BYTECAP(c) void *a, int b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(void*,SDL_memcpy,(void *a, const void *b, size_t c),(a,b,c),return) 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)
SDL_DYNAPI_PROC(void*,SDL_memmove,(void *a, const void *b, size_t c),(a,b,c),return) 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)
SDL_DYNAPI_PROC(int,SDL_memcmp,(const void *a, const void *b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_memcmp,(const void *a, const void *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_wcslen,(const wchar_t *a),(a),return) SDL_DYNAPI_PROC(size_t,SDL_wcslen,(const wchar_t *a),(a),return)
SDL_DYNAPI_PROC(size_t,SDL_wcslcpy,(wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return) 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)
SDL_DYNAPI_PROC(size_t,SDL_wcslcat,(wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return) 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)
SDL_DYNAPI_PROC(size_t,SDL_strlen,(const char *a),(a),return) SDL_DYNAPI_PROC(size_t,SDL_strlen,(const char *a),(a),return)
SDL_DYNAPI_PROC(size_t,SDL_strlcpy,(char *a, const char *b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(size_t,SDL_strlcpy,(SDL_OUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_utf8strlcpy,(char *a, const char *b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(size_t,SDL_utf8strlcpy,(SDL_OUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_strlcat,(char *a, const char *b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(size_t,SDL_strlcat,(SDL_INOUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(char*,SDL_strdup,(const char *a),(a),return) SDL_DYNAPI_PROC(char*,SDL_strdup,(const char *a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_strrev,(char *a),(a),return) SDL_DYNAPI_PROC(char*,SDL_strrev,(char *a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_strupr,(char *a),(a),return) SDL_DYNAPI_PROC(char*,SDL_strupr,(char *a),(a),return)
@ -453,7 +453,7 @@ SDL_DYNAPI_PROC(int,SDL_strcmp,(const char *a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_strncmp,(const char *a, const char *b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_strncmp,(const char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_strcasecmp,(const char *a, const char *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_strcasecmp,(const char *a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_strncasecmp,(const char *a, const char *b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_strncasecmp,(const char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_vsnprintf,(char *a, size_t b, const char *c, va_list d),(a,b,c,d),return) 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)
SDL_DYNAPI_PROC(double,SDL_acos,(double a),(a),return) SDL_DYNAPI_PROC(double,SDL_acos,(double a),(a),return)
SDL_DYNAPI_PROC(double,SDL_asin,(double a),(a),return) SDL_DYNAPI_PROC(double,SDL_asin,(double a),(a),return)
SDL_DYNAPI_PROC(double,SDL_atan,(double a),(a),return) SDL_DYNAPI_PROC(double,SDL_atan,(double a),(a),return)

View File

@ -45,6 +45,7 @@
#if !SDL_EVENTS_DISABLED #if !SDL_EVENTS_DISABLED
#include "../../events/SDL_events_c.h" #include "../../events/SDL_events_c.h"
#endif #endif
#include "../../core/windows/SDL_windows.h"
#define INITGUID /* Only set here, if set twice will cause mingw32 to break. */ #define INITGUID /* Only set here, if set twice will cause mingw32 to break. */
#include "SDL_dxjoystick_c.h" #include "SDL_dxjoystick_c.h"
@ -499,13 +500,13 @@ SDL_JoystickThread(void *_data)
if (!RegisterClassEx (&wincl)) if (!RegisterClassEx (&wincl))
{ {
return SDL_SetError("Failed to create register class for joystick autodetect.", GetLastError()); return WIN_SetError( "Failed to create register class for joystick autodetect");
} }
messageWindow = (HWND)CreateWindowEx( 0, L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL ); messageWindow = (HWND)CreateWindowEx( 0, L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL );
if ( !messageWindow ) if ( !messageWindow )
{ {
return SDL_SetError("Failed to create message window for joystick autodetect.", GetLastError()); return WIN_SetError("Failed to create message window for joystick autodetect");
} }
SDL_zero(dbh); SDL_zero(dbh);
@ -517,7 +518,7 @@ SDL_JoystickThread(void *_data)
hNotify = RegisterDeviceNotification( messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE ); hNotify = RegisterDeviceNotification( messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE );
if ( !hNotify ) if ( !hNotify )
{ {
return SDL_SetError("Failed to create notify device for joystick autodetect.", GetLastError()); return WIN_SetError( "Failed to create notify device for joystick autodetect");
} }
SDL_LockMutex( s_mutexJoyStickEnum ); SDL_LockMutex( s_mutexJoyStickEnum );

View File

@ -93,7 +93,7 @@ SDL_GetPowerInfo(int *seconds, int *percent)
{ {
const int total = sizeof(implementations) / sizeof(implementations[0]); const int total = sizeof(implementations) / sizeof(implementations[0]);
int _seconds, _percent; int _seconds, _percent;
SDL_PowerState retval; SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
int i; int i;
/* Make these never NULL for platform-specific implementations. */ /* Make these never NULL for platform-specific implementations. */
@ -106,7 +106,7 @@ SDL_GetPowerInfo(int *seconds, int *percent)
} }
for (i = 0; i < total; i++) { for (i = 0; i < total; i++) {
if (implementations[i] (&retval, seconds, percent)) { if (implementations[i](&retval, seconds, percent)) {
return retval; return retval;
} }
} }

View File

@ -258,7 +258,7 @@ SDL_ScanFloat(const char *text, double *valuep)
#endif #endif
void * void *
SDL_memset(void *dst, int c, size_t len) SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
{ {
#if defined(HAVE_MEMSET) #if defined(HAVE_MEMSET)
return memset(dst, c, len); return memset(dst, c, len);
@ -302,7 +302,7 @@ SDL_memset(void *dst, int c, size_t len)
} }
void * void *
SDL_memcpy(void *dst, const void *src, size_t len) SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
{ {
#ifdef __GNUC__ #ifdef __GNUC__
/* Presumably this is well tuned for speed. /* Presumably this is well tuned for speed.
@ -355,7 +355,7 @@ SDL_memcpy(void *dst, const void *src, size_t len)
} }
void * void *
SDL_memmove(void *dst, const void *src, size_t len) SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
{ {
#if defined(HAVE_MEMMOVE) #if defined(HAVE_MEMMOVE)
return memmove(dst, src, len); return memmove(dst, src, len);
@ -426,7 +426,7 @@ SDL_wcslen(const wchar_t * string)
} }
size_t size_t
SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen) SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
{ {
#if defined(HAVE_WCSLCPY) #if defined(HAVE_WCSLCPY)
return wcslcpy(dst, src, maxlen); return wcslcpy(dst, src, maxlen);
@ -442,7 +442,7 @@ SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
} }
size_t size_t
SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen) SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
{ {
#if defined(HAVE_WCSLCAT) #if defined(HAVE_WCSLCAT)
return wcslcat(dst, src, maxlen); return wcslcat(dst, src, maxlen);
@ -457,7 +457,7 @@ SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
} }
size_t size_t
SDL_strlcpy(char *dst, const char *src, size_t maxlen) SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{ {
#if defined(HAVE_STRLCPY) #if defined(HAVE_STRLCPY)
return strlcpy(dst, src, maxlen); return strlcpy(dst, src, maxlen);
@ -472,7 +472,7 @@ SDL_strlcpy(char *dst, const char *src, size_t maxlen)
#endif /* HAVE_STRLCPY */ #endif /* HAVE_STRLCPY */
} }
size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes) size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
{ {
size_t src_bytes = SDL_strlen(src); size_t src_bytes = SDL_strlen(src);
size_t bytes = SDL_min(src_bytes, dst_bytes - 1); size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
@ -505,7 +505,7 @@ size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes)
} }
size_t size_t
SDL_strlcat(char *dst, const char *src, size_t maxlen) SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{ {
#if defined(HAVE_STRLCAT) #if defined(HAVE_STRLCAT)
return strlcat(dst, src, maxlen); return strlcat(dst, src, maxlen);
@ -980,7 +980,7 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
} }
int int
SDL_sscanf(const char *text, const char *fmt, ...) SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
{ {
int rc; int rc;
va_list ap; va_list ap;
@ -1261,7 +1261,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
#endif /* HAVE_VSSCANF */ #endif /* HAVE_VSSCANF */
int int
SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...) SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list ap; va_list ap;
int retval; int retval;
@ -1274,7 +1274,7 @@ SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
} }
#ifdef HAVE_VSNPRINTF #ifdef HAVE_VSNPRINTF
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{ {
return vsnprintf(text, maxlen, fmt, ap); return vsnprintf(text, maxlen, fmt, ap);
} }
@ -1463,7 +1463,7 @@ SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
} }
int int
SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{ {
size_t left = maxlen; size_t left = maxlen;
char *textstart = text; char *textstart = text;

View File

@ -44,7 +44,7 @@ static Uint32 SDLTest_AssertsPassed = 0;
/* /*
* Assert that logs and break execution flow on failures (i.e. for harness errors). * Assert that logs and break execution flow on failures (i.e. for harness errors).
*/ */
void SDLTest_Assert(int assertCondition, const char *assertDescription, ...) void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
{ {
va_list list; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
@ -62,7 +62,7 @@ void SDLTest_Assert(int assertCondition, const char *assertDescription, ...)
/* /*
* Assert that logs but does not break execution flow on failures (i.e. for test cases). * Assert that logs but does not break execution flow on failures (i.e. for test cases).
*/ */
int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...) int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
{ {
va_list list; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
@ -91,7 +91,7 @@ int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...)
/* /*
* Explicitly passing Assert that logs (i.e. for test cases). * Explicitly passing Assert that logs (i.e. for test cases).
*/ */
void SDLTest_AssertPass(const char *assertDescription, ...) void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
{ {
va_list list; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];

View File

@ -68,7 +68,7 @@ char *SDLTest_TimestampToString(const time_t timestamp)
/* /*
* Prints given message with a timestamp in the TEST category and INFO priority. * Prints given message with a timestamp in the TEST category and INFO priority.
*/ */
void SDLTest_Log(const char *fmt, ...) void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list list; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
@ -86,7 +86,7 @@ void SDLTest_Log(const char *fmt, ...)
/* /*
* Prints given message with a timestamp in the TEST category and the ERROR priority. * Prints given message with a timestamp in the TEST category and the ERROR priority.
*/ */
void SDLTest_LogError(const char *fmt, ...) void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{ {
va_list list; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];

View File

@ -1095,6 +1095,8 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
SDL_VideoDisplay *display; SDL_VideoDisplay *display;
SDL_Window *other; SDL_Window *other;
CHECK_WINDOW_MAGIC(window,);
#ifdef __MACOSX__ #ifdef __MACOSX__
if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) { if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) {
window->last_fullscreen_flags = window->flags; window->last_fullscreen_flags = window->flags;