Menu

False positive: unreadVariable

CHR
2020-07-31
2022-01-22
  • CHR

    CHR - 2020-07-31

    It seems that cppcheck does not always take into account that variables can be accessed via pointer. Note that the error goes away if the 'Map' array only consists of one element.

    int main() {
        bool b0{}, b1{};
        struct {
            bool* pb;
            int val;
        }
        Map[] = { {&b0, 0}, {&b1, 1} };
    
        b0 = true; // style: Variable 'b0' is assigned a value that is never used.
    
        for (auto& m : Map)
            if (m.pb && *m.pb)
                m.val = 1;
    
        return 0;
    }
    
     
  • Daniel Marjamäki

     
  • CHR

    CHR - 2020-09-14

    A different false positive, where the decremented value is used immediately in the comparison:

    int foo(int N) {
        if (--N == 0)
            return 1;
        return 0
    }
    
     
    • CHR

      CHR - 2022-01-22

      A different false positive

      There is no FP anymore for this

       
  • Daniel Marjamäki

    Thanks! I can reproduce. I created https://trac.cppcheck.net/ticket/9901

     

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.