Skip to content

Commit 1d68fae

Browse files
authored
Add dummy macros for conditionally defined macros (#211)
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
1 parent 9cf7f12 commit 1d68fae

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

list.h

+10
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,12 @@ static inline void list_move_tail(struct list_head *node,
411411
for (entry = list_entry((head)->next, typeof(*entry), member); \
412412
&entry->member != (head); \
413413
entry = list_entry(entry->member.next, typeof(*entry), member))
414+
#else
415+
/* The negative width bit-field makes a compile-time error for use of this. It
416+
* works in the same way as BUILD_BUG_ON_ZERO macro of Linux kernel.
417+
*/
418+
#define list_for_each_entry(entry, head, member) \
419+
for (entry = (void *) 1; sizeof(struct { int : -1; }); ++(entry))
414420
#endif
415421

416422
/**
@@ -450,6 +456,10 @@ static inline void list_move_tail(struct list_head *node,
450456
safe = list_entry(entry->member.next, typeof(*entry), member); \
451457
&entry->member != (head); entry = safe, \
452458
safe = list_entry(safe->member.next, typeof(*entry), member))
459+
#else
460+
#define list_for_each_entry_safe(entry, safe, head, member) \
461+
for (entry = safe = (void *) 1; sizeof(struct { int : -1; }); \
462+
++(entry), ++(safe))
453463
#endif
454464

455465
#undef __LIST_HAVE_TYPEOF

scripts/checksums

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
db6784ff3917888db4d1dceaa0570d99ed40e762 queue.h
2-
a35ff719849dbe38d903576a332989c5ba7242bf list.h
2+
27d7a57c6bab59beda9178f240db1aa7c0062361 list.h
33
3bb0192cee08d165fd597a9f6fbb404533e28fcf scripts/check-commitlog.sh

0 commit comments

Comments
 (0)