From 6aec6da4c3daad1259f9c8dedf933a1be1ade51a Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 28 Jun 2020 17:45:07 -0400 Subject: [PATCH] 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. --- include/SDL_stdinc.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index ad1344d36..a79354c80 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