Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sat, 16 Nov 2019 17:29:43 UTC Commit: d0b67df06967e6a9b5d6c18fce0ef35a211714b5 https://github.com/geany/geany/commit/d0b67df06967e6a9b5d6c18fce0ef35a211714...
Log Message: ----------- Rewrite HL_N_ENTRIES macro to avoid a GCC8 false positive warning
GCC 8 introduced `-Wsizeof-pointer-div` which is enabled by `-Wall` and warns for sizeof divisions that look like they would compute the size of a static array but are called on something on which this doesn't work (e.g. a pointer as LHS). This is quite reasonable and useful, but it fails to detect the case where the computation is guarded against being called on problematic values, like our HL_N_ENTRIES() macro that accepts NULLs but won't use the sizeof computation result then.
Work around this by implementing HL_N_ENTRIES() macro in a way that cannot trigger such a warning yet yield the same result.
Modified Paths: -------------- src/highlightingmappings.h
Modified: src/highlightingmappings.h 12 lines changed, 10 insertions(+), 2 deletions(-) =================================================================== @@ -68,8 +68,16 @@ typedef struct #define EMPTY_KEYWORDS ((HLKeyword *) NULL) #define EMPTY_PROPERTIES ((HLProperty *) NULL)
-/* like G_N_ELEMENTS() but supports @array being NULL (for empty entries) */ -#define HL_N_ENTRIES(array) ((array != NULL) ? G_N_ELEMENTS(array) : 0) +/* like G_N_ELEMENTS() but supports @array being NULL (for empty entries). + * The straightforward `((array != NULL) ? G_N_ELEMENTS(array) : 0)` is not + * used here because of GCC8's -Wsizeof-pointer-div which doesn't realize the + * result of G_N_ELEMENTS() is never actually used when `array` is NULL. + * This implementation gives the same result as the LHS of the division + * becomes 0 when `array` is NULL, but is not a case that GCC can misinterpret + * and warn about. + * An alternative solution would be using zero-sized arrays instead of NULLs, + * but zero-sized arrays are forbidden by ISO C */ +#define HL_N_ENTRIES(array) ((sizeof(array) * ((array) != NULL)) / sizeof((array)[0]))
/* Abaqus */
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).