From 00b37f4b1f7acb8586f94e0dbeab9c9f8dbb5b30 Mon Sep 17 00:00:00 2001 From: Lumynous Date: Wed, 26 Feb 2025 17:41:04 +0800 Subject: [PATCH 1/3] Add dummy macros for conditionally defined macros cppcheck reports "unknownMacro" when a conditionally defined macro is used. This patch adds dummy macros to make code pass the static analytics without other effects. The assignments and increments make cppcheck consider the variables are used to suppress potential reports about uninitialized variables, unused variables, and can-be-constant variables. The pointers with value 1 instead of NULL suppress reports about indirectly getting value of null pointers. Closes #210. Change-Id: Ia8db49c0c71ab82d5da10ce389f57ebb69c99051 --- list.h | 7 +++++++ scripts/checksums | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/list.h b/list.h index db6e6bc81..61a80c48d 100644 --- a/list.h +++ b/list.h @@ -411,6 +411,9 @@ static inline void list_move_tail(struct list_head *node, for (entry = list_entry((head)->next, typeof(*entry), member); \ &entry->member != (head); \ entry = list_entry(entry->member.next, typeof(*entry), member)) +#else +#define list_for_each_entry(entry, head, member) \ + for (entry = (void *) 1; sizeof(struct { int : -1; }); ++(entry)) #endif /** @@ -450,6 +453,10 @@ static inline void list_move_tail(struct list_head *node, safe = list_entry(entry->member.next, typeof(*entry), member); \ &entry->member != (head); entry = safe, \ safe = list_entry(safe->member.next, typeof(*entry), member)) +#else +#define list_for_each_entry_safe(entry, safe, head, member) \ + for (entry = safe = (void *) 1; sizeof(struct { int : -1; }); \ + ++(entry), ++(safe)) #endif #undef __LIST_HAVE_TYPEOF diff --git a/scripts/checksums b/scripts/checksums index 85657218d..217595f6d 100644 --- a/scripts/checksums +++ b/scripts/checksums @@ -1,3 +1,3 @@ db6784ff3917888db4d1dceaa0570d99ed40e762 queue.h -a35ff719849dbe38d903576a332989c5ba7242bf list.h +78828505183bf0444f574c0a33a4a1f5e3231994 list.h 3bb0192cee08d165fd597a9f6fbb404533e28fcf scripts/check-commitlog.sh From 461781b77e5b6d88277e39b1e12b1e0178811076 Mon Sep 17 00:00:00 2001 From: Lumynous Date: Thu, 27 Feb 2025 10:00:32 +0800 Subject: [PATCH 2/3] Add comment for the dummy macro compilation guard Change-Id: I1da359df006f058c3e27a0d4bc91b50c4441a1da --- list.h | 1 + scripts/checksums | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/list.h b/list.h index 61a80c48d..c196c5db9 100644 --- a/list.h +++ b/list.h @@ -412,6 +412,7 @@ static inline void list_move_tail(struct list_head *node, &entry->member != (head); \ entry = list_entry(entry->member.next, typeof(*entry), member)) #else +// The negative width bit-field makes a compile-time error for use of this. #define list_for_each_entry(entry, head, member) \ for (entry = (void *) 1; sizeof(struct { int : -1; }); ++(entry)) #endif diff --git a/scripts/checksums b/scripts/checksums index 217595f6d..f5a445ad2 100644 --- a/scripts/checksums +++ b/scripts/checksums @@ -1,3 +1,3 @@ db6784ff3917888db4d1dceaa0570d99ed40e762 queue.h -78828505183bf0444f574c0a33a4a1f5e3231994 list.h +943e0653daa1d51c9f61d1652a644588af5969e2 list.h 3bb0192cee08d165fd597a9f6fbb404533e28fcf scripts/check-commitlog.sh From e211e84162beb658264198720af8bbc7e7383802 Mon Sep 17 00:00:00 2001 From: Lumynous Date: Thu, 27 Feb 2025 12:49:48 +0800 Subject: [PATCH 3/3] Refine comment for dummy macro compilation guard Change-Id: I85c21c24bbd5856a5a22cbd983f5150a56c13345 --- list.h | 4 +++- scripts/checksums | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/list.h b/list.h index c196c5db9..065ab3dc9 100644 --- a/list.h +++ b/list.h @@ -412,7 +412,9 @@ static inline void list_move_tail(struct list_head *node, &entry->member != (head); \ entry = list_entry(entry->member.next, typeof(*entry), member)) #else -// The negative width bit-field makes a compile-time error for use of this. +/* The negative width bit-field makes a compile-time error for use of this. It + * works in the same way as BUILD_BUG_ON_ZERO macro of Linux kernel. + */ #define list_for_each_entry(entry, head, member) \ for (entry = (void *) 1; sizeof(struct { int : -1; }); ++(entry)) #endif diff --git a/scripts/checksums b/scripts/checksums index f5a445ad2..3495f023a 100644 --- a/scripts/checksums +++ b/scripts/checksums @@ -1,3 +1,3 @@ db6784ff3917888db4d1dceaa0570d99ed40e762 queue.h -943e0653daa1d51c9f61d1652a644588af5969e2 list.h +27d7a57c6bab59beda9178f240db1aa7c0062361 list.h 3bb0192cee08d165fd597a9f6fbb404533e28fcf scripts/check-commitlog.sh