Menu

cppcheck-Uninitialized variable: port.isActive [uninitvar]

chris lin
2022-04-08
2022-04-10
  • chris lin

    chris lin - 2022-04-08

    I checked my project with cppcheck and got the Uninitialized variable: port.isActive [uninitvar] error.
    This is my function code

     // 0 Unknow 1 Not available 2 Available
                if (port.available == 2 || port.available == 0) {
                    port.portId   = jPort["Name"].toString();
                    port.portName = jPort["Description"].toString();
                    port.cardId   = cardId;
                    port.cardName = cardName;
                    // 只添加输入port
                    if (port.isInputPort()) {
                        m_availableInputPorts.insert(port.portId, port);
                        //qDebug() << " " << port;
                    }
                }
    

    This is my struct code

    struct Port {
            QString  portId;
            QString portName;
            QString cardName;
            int     available {1};
            int     cardId;
            bool    isActive {false};
    
            bool isInputPort() const;
            bool isLoopback() const;
        };
    

    I have already initialized the structure whi is this error still report,is it a false alarm?

     
  • CHR

    CHR - 2022-04-08

    Which version do you use? How is the variable portdefined in your code?
    I don't get a warning with current head for

    struct S {
        int i{ 1 };
        bool b{ false };
    };
    void f() {
        S s;
        if (s.i == 2 || s.b) {}
    }
    
     
  • chris lin

    chris lin - 2022-04-09

    I am using cppcheck version 2.7 and isAative is a field in the Port structure,but it's not used in this function.

     
  • chris lin

    chris lin - 2022-04-09

    I am using cppcheck version 2.7 and isAative is a field in the Port structure,but it's not used in this function.

     
  • Daniel Marjamäki

    Can you provide a small code example that reproduce the problem? The code CHR tried didn't reproduce the problem.

    Probably it's easiest that you reduce your real code. If the code is pointless etc does not matter it's just important that we can reproduce the FP.

    I think it's likely that there is a detail in your code that confuses Cppcheck somehow. And that detail is very difficult to guess.

     

    Last edit: Daniel Marjamäki 2022-04-09
  • chris lin

    chris lin - 2022-04-10

    Thank you,I understand

     

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.