summaryrefslogtreecommitdiff
path: root/include/SDL_stdinc.h
diff options
context:
space:
mode:
authorRyan C. Gordon <icculus@icculus.org>2015-01-05 01:41:42 -0500
committerRyan C. Gordon <icculus@icculus.org>2015-01-05 01:41:42 -0500
commitc6ad924b96d6d0f7fa1151d760e99f326b2fc84e (patch)
treea6706a54652f13819c01eca1e3d72801b3a631e5 /include/SDL_stdinc.h
parent3b8ee2b19512959c9729792770579f4f9374a2fe (diff)
downloadsdl-c6ad924b96d6d0f7fa1151d760e99f326b2fc84e.tar.gz
Clang static analysis builds should use C runtime directly.
This is a little macro magic to use malloc() directly instead of SDL_malloc(), etc, so static analysis tests that know about the C runtime can function properly, and understand that we are dealing with heap allocations, etc. This changed our static analysis report from 5 outstanding bugs to 30. 5x as many bugs were hidden by SDL_malloc() not being recognized as malloc() by the static analyzer!
Diffstat (limited to 'include/SDL_stdinc.h')
-rw-r--r--include/SDL_stdinc.h38
1 files changed, 33 insertions, 5 deletions
diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h
index 853a440ac..7a061a9c8 100644
--- a/include/SDL_stdinc.h
+++ b/include/SDL_stdinc.h
@@ -379,11 +379,6 @@ SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
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(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);
-}
-
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);
@@ -480,6 +475,39 @@ extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
+/* force builds using Clang's static analysis tools to use literal C runtime
+ here, since there are possibly tests that are ineffective otherwise. */
+#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
+#define SDL_malloc malloc
+#define SDL_calloc calloc
+#define SDL_realloc realloc
+#define SDL_free free
+#define SDL_memset memset
+#define SDL_memcpy memcpy
+#define SDL_memmove memmove
+#define SDL_memcmp memcmp
+#define SDL_strlen strlen
+#define SDL_strlcpy strlcpy
+#define SDL_strlcat strlcat
+#define SDL_strdup strdup
+#define SDL_strchr strchr
+#define SDL_strrchr strrchr
+#define SDL_strstr strstr
+#define SDL_strcmp strcmp
+#define SDL_strncmp strncmp
+#define SDL_strcasecmp strcasecmp
+#define SDL_strncasecmp strncasecmp
+#define SDL_sscanf sscanf
+#define SDL_vsscanf vsscanf
+#define SDL_snprintf snprintf
+#define SDL_vsnprintf vsnprintf
+#endif
+
+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);
+}
+
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}