stdinc: Let Clang static analysis see more C runtime functions. For systems without strlcpy and strlcat, just declare them as if they exist; the analyzer possibly still knows the details of these functions and can utilize that in its analysis. Most of this patch was from meyraud705 at gmail and Martin Gerhardy. Thanks! Fixes Bugzilla #5163.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h
index ad1344d..a79354c 100644
--- a/include/SDL_stdinc.h
+++ b/include/SDL_stdinc.h
@@ -577,6 +577,17 @@ extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
/* 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)
+
+/* The analyzer knows about strlcpy even when the system doesn't provide it */
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char* dst, const char* src, size_t size);
+#endif
+
+/* The analyzer knows about strlcat even when the system doesn't provide it */
+#ifndef HAVE_STRLCAT
+size_t strlcat(char* dst, const char* src, size_t size);
+#endif
+
#define SDL_malloc malloc
#define SDL_calloc calloc
#define SDL_realloc realloc
@@ -585,16 +596,23 @@ extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
#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_strlen strlen
+#define SDL_wcslen wcslen
+#define SDL_wcslcpy wcslcpy
+#define SDL_wcslcat wcslcat
#define SDL_strdup strdup
+#define SDL_wcsdup wcsdup
#define SDL_strchr strchr
#define SDL_strrchr strrchr
#define SDL_strstr strstr
+#define SDL_wcsstr wcsstr
#define SDL_strtokr strtok_r
#define SDL_strcmp strcmp
+#define SDL_wcscmp wcscmp
#define SDL_strncmp strncmp
+#define SDL_wcsncmp wcsncmp
#define SDL_strcasecmp strcasecmp
#define SDL_strncasecmp strncasecmp
#define SDL_sscanf sscanf