| Summary: | clang static analyser error if strlcpy and strlcat are not available | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Martin Gerhardy <martin.gerhardy> |
| Component: | build | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | minor | ||
| Priority: | P2 | CC: | icculus, meyraud705 |
| Version: | HG 2.0 | Keywords: | target-2.0.14 |
| Hardware: | All | ||
| OS: | Linux | ||
| Attachments: |
check for strl*
check for strl* v2 |
||
Clang-tidy (and clang) finds more warning if you use standard functions. You should install libbsd-dev and add '#include <bsd/string.h>' before '#define SDL_strlcpy strlcpy' to get the missing functions. We already make sure SDL_malloc becomes standard malloc() when doing static analysis, it would be smart to handle these, too. Created attachment 4360 [details]
check for strl*
Here a patch that checks for HAVE_STRLCPY and HAVE_STRLCAT, then fallback to include bsd/string.h.
It uses '__has_include", which is a clang extension. But that should be fine as this code is only used for clang static analysis.
It also defines SDL_wcs* functions to standard functions.
(In reply to meyraud705 from comment #3) > Here a patch that checks for HAVE_STRLCPY and HAVE_STRLCAT, then fallback to > include bsd/string.h. But I assume Clang static analysis can't perform any special strlcpy() checks if you have to install libbsd-dev to get this function, right...? --ryan. Created attachment 4399 [details]
check for strl* v2
I use clang-tidy and it knows standard functions enough to perform checks as long as the function is declared.
Attached version 2 of my patch: libbsd is actually not needed, only declares strlcat and strlcpy if not available.
I made a slight change to the #ifdefs in this patch--we want SDL_strlcpy defined to strlcpy no matter what, and just declare the C runtime function if the system didn't provide it--but otherwise, this looks good, and I've put it in revision control as https://hg.libsdl.org/SDL/rev/92ea0212b095 Thanks! --ryan. |
If I run clang-tidy-10 I get some errors that are related to #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) #define SDL_strlcpy strlcpy #define SDL_strlcat strlcat I wonder whether it would be a good idea to check for HAVE_STRLCPY before overriding them? The error for strlcpy is: ------------------------------------------------ error: use of undeclared identifier 'strlcpy'; did you mean 'strncpy'? [clang-diagnostic-error] SDL_strlcpy(&buf[idx], value.c_str(), remaining); ^~~~~~~~~~~ strncpy /usr/include/SDL2/SDL_stdinc.h:578:21: note: expanded from macro 'SDL_strlcpy' #define SDL_strlcpy strlcpy ^ /usr/include/string.h:125:14: note: 'strncpy' declared here extern char *strncpy (char *__restrict __dest, ^ 46 warnings and 1 error generated. ------------------------------------------------