Menu

loop macros

2021-08-12
2021-08-21
  • Paul Aitken

    Paul Aitken - 2021-08-12

    How can I tell cppcheck that "LIST_FOREACH(...)" and "cds_list_for_each_entry_rcu(...)" are loops rather than function calls?

    eg, the code below reports some false positives which do not appear when "cds_list_for_each_entry_rcu" is replaced with "for":

    c.c:7:31: style: Condition '!primary' is always true [knownConditionTrueFalse]
    if (!primary)
    ^
    c.c:3:31: note: Assignment 'primary=0', assigned value is 0
    in_addr_t primary = 0;
    ^
    c.c:7:31: note: Condition '!primary' is always true
    if (!primary)
    ^

    somefn(void)
    {
              in_addr_t primary = 0;
    
              cds_list_for_each_entry_rcu(ifa, &ifp->if_addrhead, ifa_link) {
                              // ...
                              if (!primary)
                                      primary = something_else;
                               // ...
              }
    
              return primary;
    }
    
     
  • Paul Aitken

    Paul Aitken - 2021-08-20

    @danielmarjamaki any thoughts on this? Thanks.

     
  • Daniel Marjamäki

    I would suggest that you define cds_list_for_each_entry_rcu(A,B,C) somehow. Somehow.. use a for loop..

    I can't suggest anything specific because I don't know what the variables are and how they are used in the code.

    If that makes the macro definition easier.. I believe you can expand it to a c++ range for loop , as far as I know Cppcheck should treat that the same in C code.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.