Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Wed, 25 Oct 2023 19:29:02 UTC Commit: ba6fc4a4fa48239daca7350ec05d25e44cc89169 https://github.com/geany/geany/commit/ba6fc4a4fa48239daca7350ec05d25e44cc891...
Log Message: ----------- Merge pull request #2398 from b4n/gcc8-array-size
Rewrite HL_N_ENTRIES macro to avoid a GCC8 false positive warning
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).