With the new outOfBounds check I get a lot of new errors because a datatype I use is declared as
an array-like container in a .cfg file. (see below).
The real datatype is initialized in it's constructor and has a fixed size.
Is there a way to make the size known in the .cfg file so the outOfBounds check can make sense of it and not flag every use of the [] operator as an error?
Or can I selectively suppress the check for specific datatypes?
On another note: Are there any improvements for defining operator overloads in the .cfg file in the new 2.2?
Both .cfg and the example are extracted out of more complex codebase. I'll try to verify that it gives the error with this minmal extract too, but it may take me a moment. I'll comment here once I can verify.
PS.: The size to which the custom array-like type is initialized is of course DEMO_CONST in the example. But if you want to try with a real world number, lets just assume its 64.
Last edit: Ronny Soak 2020-10-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can now verify that the above code examples indeed produce the outOfBounds error.
<?xmlversion="1.0"encoding="UTF-8"?><resultsversion="2"><cppcheckversion="2.2"/><errors><errorid="containerOutOfBounds"severity="error"msg="Out of bounds access in expression 'result[index]' because 'result' is empty."verbose="Out of bounds access in expression 'result[index]' because 'result' is empty."cwe="398"hash="7410409346732110854"><locationfile="test.cpp"line="10"column="13"info="Access out of bounds"/><symbol>result</symbol></error><errorid="unmatchedSuppression"severity="information"msg="Unmatched suppression: missingInclude"verbose="Unmatched suppression: missingInclude"/></errors></results>
I've edited the above examples to be complete (missing <def> in .cfg) and compilable (put cppcheck marker after //).</def>
Last edit: Ronny Soak 2020-10-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
With the new outOfBounds check I get a lot of new errors because a datatype I use is declared as
an array-like container in a .cfg file. (see below).
The real datatype is initialized in it's constructor and has a fixed size.
Is there a way to make the size known in the .cfg file so the outOfBounds check can make sense of it and not flag every use of the [] operator as an error?
Or can I selectively suppress the check for specific datatypes?
On another note: Are there any improvements for defining operator overloads in the .cfg file in the new 2.2?
Thanks
Last edit: Ronny Soak 2020-10-06
could you show a short c++ code also that generates the FP.
what should the size be?
Last edit: Daniel Marjamäki 2020-10-05
Example code would be
For which in the .cfg posted above the line
needs to be added as well.
The full error message is
CppCheck is started with
Both .cfg and the example are extracted out of more complex codebase. I'll try to verify that it gives the error with this minmal extract too, but it may take me a moment. I'll comment here once I can verify.
PS.: The size to which the custom array-like type is initialized is of course DEMO_CONST in the example. But if you want to try with a real world number, lets just assume its 64.
Last edit: Ronny Soak 2020-10-06
I can now verify that the above code examples indeed produce the outOfBounds error.
I've edited the above examples to be complete (missing <def> in .cfg) and compilable (put cppcheck marker after //).</def>
Last edit: Ronny Soak 2020-10-06