Menu

False positive containerOutOfBounds with nested std::vector

2024-12-18
2024-12-18
  • Frank Winklmeier

    The following results in a false positive containerOutOfBounds defect:

    void f() {
      auto v = std::vector<std::vector<S*>>(3, std::vector<S*>());
      v[2];
    }
    

    With cppcheck 2.16.0 (and also the current HEAD):

    test.cxx:3:4: error: Out of bounds access in 'v[2]', if 'v' size is 2 and '2' is 2 [containerOutOfBounds]
      v[2];
       ^
    

    The problem disappears if one omits the default value, i.e. uses auto v = std::vector<std::vector<S*>>(3).

     
  • CHR

    CHR - 2024-12-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.