Menu

False positive [containerOutOfBounds] with std::map<int, >

2022-06-23
2022-06-24
  • Ruud Althuizen

    Ruud Althuizen - 2022-06-23

    When using a std::map with int for the key the bounds are checked as if it's an array. Tested on 2.8.

    std::map<int, std::string> myMap = {
      {1, "1"},
      {2, "2"},
      {3, "3"},
      {4, "4"},
      {5, "5"}};
    
    for (int i = 1; i <= 5; ++i)
    {
      // Out of bounds access in 'myMap.at(i)', if 'myMap' size is 5 and 'i' is 5
      int myInt = myMap.at(i);
    }
    
     

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.