Menu

a case of CWE: 398

AlexHsieh
2024-08-07
2024-08-07
  • AlexHsieh

    AlexHsieh - 2024-08-07

    Hi,
    I use cppcheck-2.14.1 to check the following code

    #include <string>
    using namespace std;
    
    int main() {
        string ss[1];
        ss->clear();
        //(*ss).clear(); // OK
        //ss[0].clear(); // OK
        string s;
        s.append(ss[i]);
        return 0;
    }
    

    , and get
    CWE: 398
    Out of bounds access in expression 'ss[i]' because 'ss' is empty.

    Is this a false positive?

     
  • CHR

    CHR - 2024-08-07

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

     
  • AlexHsieh

    AlexHsieh - 2024-08-07

    Thank you for the confirmation.

     

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.