Menu

Cppcheck 2.4 std::array out of bounds possible false positive

2021-03-22
2021-03-23
  • Steffen Fuchs

    Steffen Fuchs - 2021-03-22

    Hi,

    I think I´ve found a false positive regarding std::array. Consider the following code:

    int main (){                         
                    std::array<float, 10>       result = {};         
                    for (size_t j = 0; j < 10; ++j) {      result[j] = 1.0F;}               
    }
    

    Which result with V2.4 in the following error:
    CWE: 398
    Out of bounds access in expression 'result[j]' because 'result' is empty.

    If I change the code to the error is gone:

    int main (){                         
                    std::array<float, 10>       result {};             
                    for (size_t j = 0; j < 10; ++j) {      result[j] = 1.0F;}               
    }
    

    V2.3 did not have any issues with the code!

    Best regards
    Steffen

     
  • CHR

    CHR - 2021-03-23

    Thanks for the report, I have created a ticket here: https://trac.cppcheck.net/ticket/10216

     
    👍
    1

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.