include/SDL_stdinc.h
changeset 8820 0e935d5b193a
parent 8583 fb2933ca805f
child 8840 9b6ddcbdea65
     1.1 --- a/include/SDL_stdinc.h	Wed Jun 04 10:56:43 2014 -0700
     1.2 +++ b/include/SDL_stdinc.h	Wed Jun 04 10:56:56 2014 -0700
     1.3 @@ -166,6 +166,50 @@
     1.4  /* @} *//* Basic data types */
     1.5  
     1.6  
     1.7 +/* Annotations to help code analysis tools */
     1.8 +#ifdef SDL_DISABLE_ANALYZE_MACROS
     1.9 +#define SDL_IN_BYTECAP(x)
    1.10 +#define SDL_INOUT_Z_CAP(x)
    1.11 +#define SDL_OUT_Z_CAP(x)
    1.12 +#define SDL_OUT_CAP(x)
    1.13 +#define SDL_OUT_BYTECAP(x)
    1.14 +#define SDL_OUT_Z_BYTECAP(x)
    1.15 +#define SDL_PRINTF_FORMAT_STRING
    1.16 +#define SDL_SCANF_FORMAT_STRING
    1.17 +#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
    1.18 +#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
    1.19 +#else
    1.20 +#if _MSC_VER >= 1600 /* VS 2010 and above */
    1.21 +#include <sal.h>
    1.22 +
    1.23 +#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
    1.24 +#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
    1.25 +#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
    1.26 +#define SDL_OUT_CAP(x) _Out_cap_(x)
    1.27 +#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
    1.28 +#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
    1.29 +
    1.30 +#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
    1.31 +#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
    1.32 +#else
    1.33 +#define SDL_IN_BYTECAP(x)
    1.34 +#define SDL_INOUT_Z_CAP(x)
    1.35 +#define SDL_OUT_Z_CAP(x)
    1.36 +#define SDL_OUT_CAP(x)
    1.37 +#define SDL_OUT_BYTECAP(x)
    1.38 +#define SDL_OUT_Z_BYTECAP(x)
    1.39 +#define SDL_PRINTF_FORMAT_STRING
    1.40 +#define SDL_SCANF_FORMAT_STRING
    1.41 +#endif
    1.42 +#if defined(__GNUC__)
    1.43 +#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
    1.44 +#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
    1.45 +#else
    1.46 +#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
    1.47 +#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
    1.48 +#endif
    1.49 +#endif /* SDL_DISABLE_ANALYSE_MACROS */
    1.50 +
    1.51  #define SDL_COMPILE_TIME_ASSERT(name, x)               \
    1.52         typedef int SDL_dummy_ ## name[(x) * 2 - 1]
    1.53  /** \cond */
    1.54 @@ -259,7 +303,7 @@
    1.55  extern DECLSPEC int SDLCALL SDL_toupper(int x);
    1.56  extern DECLSPEC int SDLCALL SDL_tolower(int x);
    1.57  
    1.58 -extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
    1.59 +extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
    1.60  
    1.61  #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
    1.62  #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
    1.63 @@ -294,24 +338,24 @@
    1.64  }
    1.65  
    1.66  
    1.67 -extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
    1.68 +extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
    1.69  
    1.70 -SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
    1.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)
    1.72  {
    1.73      return SDL_memcpy(dst, src, dwords * 4);
    1.74  }
    1.75  
    1.76 -extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
    1.77 +extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
    1.78  extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
    1.79  
    1.80  extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
    1.81 -extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
    1.82 -extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
    1.83 +extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
    1.84 +extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
    1.85  
    1.86  extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
    1.87 -extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
    1.88 -extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
    1.89 -extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
    1.90 +extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
    1.91 +extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
    1.92 +extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
    1.93  extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
    1.94  extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
    1.95  extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
    1.96 @@ -340,10 +384,10 @@
    1.97  extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
    1.98  extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
    1.99  
   1.100 -extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
   1.101 +extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
   1.102  extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
   1.103 -extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
   1.104 -extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
   1.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);
   1.106 +extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);
   1.107  
   1.108  #ifndef HAVE_M_PI
   1.109  #ifndef M_PI