stdinc: Let Clang static analysis see more C runtime functions. default tip
authorRyan C. Gordon <icculus@icculus.org>
Sun, 28 Jun 2020 17:45:07 -0400
changeset 1394092ea0212b095
parent 13939 2173f488608f
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
     1.1 --- a/include/SDL_stdinc.h	Sun Jun 28 16:23:05 2020 -0400
     1.2 +++ b/include/SDL_stdinc.h	Sun Jun 28 17:45:07 2020 -0400
     1.3 @@ -577,6 +577,17 @@
     1.4  /* force builds using Clang's static analysis tools to use literal C runtime
     1.5     here, since there are possibly tests that are ineffective otherwise. */
     1.6  #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
     1.7 +
     1.8 +/* The analyzer knows about strlcpy even when the system doesn't provide it */
     1.9 +#ifndef HAVE_STRLCPY
    1.10 +size_t strlcpy(char* dst, const char* src, size_t size);
    1.11 +#endif
    1.12 +
    1.13 +/* The analyzer knows about strlcat even when the system doesn't provide it */
    1.14 +#ifndef HAVE_STRLCAT
    1.15 +size_t strlcat(char* dst, const char* src, size_t size);
    1.16 +#endif
    1.17 +
    1.18  #define SDL_malloc malloc
    1.19  #define SDL_calloc calloc
    1.20  #define SDL_realloc realloc
    1.21 @@ -585,16 +596,23 @@
    1.22  #define SDL_memcpy memcpy
    1.23  #define SDL_memmove memmove
    1.24  #define SDL_memcmp memcmp
    1.25 -#define SDL_strlen strlen
    1.26  #define SDL_strlcpy strlcpy
    1.27  #define SDL_strlcat strlcat
    1.28 +#define SDL_strlen strlen
    1.29 +#define SDL_wcslen wcslen
    1.30 +#define SDL_wcslcpy wcslcpy
    1.31 +#define SDL_wcslcat wcslcat
    1.32  #define SDL_strdup strdup
    1.33 +#define SDL_wcsdup wcsdup
    1.34  #define SDL_strchr strchr
    1.35  #define SDL_strrchr strrchr
    1.36  #define SDL_strstr strstr
    1.37 +#define SDL_wcsstr wcsstr
    1.38  #define SDL_strtokr strtok_r
    1.39  #define SDL_strcmp strcmp
    1.40 +#define SDL_wcscmp wcscmp
    1.41  #define SDL_strncmp strncmp
    1.42 +#define SDL_wcsncmp wcsncmp
    1.43  #define SDL_strcasecmp strcasecmp
    1.44  #define SDL_strncasecmp strncasecmp
    1.45  #define SDL_sscanf sscanf