Menu

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

2022-06-23
2022-06-23
  • 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.

    std::map<int, std::string=""> myMap = {
    {1, "1"},
    {2, "2"},
    {3, "3"},
    {4, "4"},
    {5, "5"}};</int,>

    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);
    }

     
  • CHR

    CHR - 2022-06-23

    Thanks for reporting, this PR fixes the issue: https://github.com/danmar/cppcheck/pull/4230

     

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.