Closed
Description
Some macros are conditionally defined, such as list_for_each_entry_safe
, which is only defined if typeof
is supported. CppCheck reports unknownMacro
when these macros are used because it checks each branch of conditional compilation (as the --force
option presents) and they are not always defined.
A possible solution is to define dummy macros to bypass the static analytics:
#if __LIST_HAVE_TYPEOF
#define list_for_each_entry_safe(entry, safe, head, member) \
for (entry = list_entry((head)->next, typeof(*entry), member), \
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
The assignments and increments make CppCheck consider the variables are used and suppress potential reports about uninitialized variables, unused variables, and can-be-constant variables. The pointers with value 1
instead of NULL
suppress reports about dereferencing null pointers.
This way, code can pass the static analytics without changes to the macro parameters.
Metadata
Metadata
Assignees
Labels
No labels