Menu

FP knownConditionTrueFalse with pointer-to-pointer assigment

2023-02-21
2023-02-21
  • Tobias Mark

    Tobias Mark - 2023-02-21

    Version: 2.10

    struct Bar { Bar *next; };
    
    void func(const Bar *b1, Bar *b2) {
        if(b1 != b2) {
            Bar **bp = &b2;
            while(*bp && *bp != b1) {
                bp = &(*bp)->next;
            }
        }
    }
    

    gives

    test.c:10:19: style: Condition '*bp!=b1' is always true [knownConditionTrueFalse]
     while(*bp && *bp != b1) {
    

    Maybe the error is with reading the expression. When splitting the inner most line to:

                 Bar *t = *bp;
                bp = &t->next;
    

    it's ok.

     

    Last edit: Tobias Mark 2023-02-21
  • CHR

    CHR - 2023-02-21

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11574

     

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.