Menu

2.3: false positive?

jacob s
2020-12-12
2020-12-22
  • jacob s

    jacob s - 2020-12-12

    hi,
    with the following code:

    #include <stdbool.h>
    
    // cppcheck-suppress unusedFunction
    bool fun(const int input, const int input_b) {
        bool ret = true;
        switch (input) {
            case 1:
                ret = false;
                if (!input_b)
                    break;
                ret = true;
              break;
        }
        return ret;
    }
    

    i get a redundantAssignment warning:

    file.c:39:17: style: Variable 'ret' is reassigned a value before the old one has been used. [redundantAssignment]
                ret = true;
                    ^
    file.c:36:17: note: ret is assigned
                ret = false;
                    ^
    file.c:39:17: note: ret is overwritten
                ret = true;
                    ^
    

    which i believe is a false positive.

    thanks, jacob

     
  • CHR

    CHR - 2020-12-21

    Oddly, the warning disappears when replacing true and false with integers 1 and 0, respectively.

     
  • Daniel Marjamäki

    Thanks! I have created ticket https://trac.cppcheck.net/ticket/10058

     

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.