Menu

uninitvar false positive

2023-06-17
2023-06-18
  • Pascal Roobrouck

    as I am new to cppcheck I am not sure this is a false positive or an error in my code...

    my unit test is

    void test_sensorCollection_initalize() {
        sensorCollection aCollection;
        TEST_ASSERT_EQUAL_UINT32(0, aCollection.actualNumberOfSensors);
    }
    

    cppcheck complains

    [high:error] Uninitialized variable: aCollection.actualNumberOfSensors [uninitvar]
    

    but in the sensorCollection class there is a straightforward braced initialization of this memberVariable

    uint32_t actualNumberOfSensors{0};
    

    using cppcheck from within PlatformIO, and it is version 2.7

     
  • Daniel Marjamäki

    Can you provide some little example code that reproduces the error?

    It sounds like a false positive to me.

    I can't reproduce with this code:

    class sensorCollection {
        int actualNumberOfSensors{0};
    };
    
    void test_sensorCollection_initalize() {
        sensorCollection aCollection;
        if (0 == aCollection.actualNumberOfSensors){}
    }
    

    There might be some little detail in your code that confuses Cppcheck.. personally I would suggest that you repeat this procedure below until you have a small code example:

    • remove/simplify some piece of code
    • run cppcheck
    • if error is not written by cppcheck , undo step 1
    • repeat
     

    Last edit: Daniel Marjamäki 2023-06-18

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.