Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cppcheck out of bounds when it's not

When setting the size of a std::array in a class definition using a static const as the size, cppcheck doesn't know how large the array is. So it thinks I'm out of bounds when I'm not

Doing a #define seems to solve the problem so this is an academic question.

class A
{
    A() : myArr()
    {
        myArr[0]=100;
    }
    static const int SOMEVAL = 4;

    std::array<double, SOMEVAL+1> myArr;

    int getVal() { return myArr[1]; };

}
int main(void)
{

    A myA;
    myA.getVal();

}

Any thoughts?

like image 987
BLowe Avatar asked Dec 04 '25 15:12

BLowe


1 Answers

This was a defect in cppcheck:

https://trac.cppcheck.net/ticket/9202

Which has been fixed in the 1.89 release:

https://trac.cppcheck.net/changeset/121093658d788126d5f94792c4ea00447fdbb979/

like image 170
Paul Fultz II Avatar answered Dec 06 '25 22:12

Paul Fultz II



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!