The code below results in a containerOutOfBounds warning with v2.3, The idea is that Read() would fill the vector via pointer. It seems that cppcheck loses track of the pointer when more than one set of braces is involved.
#include<string>
#include<vector>structT {
std::vector<std::wstring>*pvs;
};structS {
Tt;
};longRead(S&s);longRead(T&t);size_ttest() {
std::vector<std::wstring>Arr;//thisisfineTt= { &Arr };Read(t);//additionalbracestriggertheerror//Tt= { { &Arr } };//Read(t);//bracesarerequiredhere->error//Ss= { { &Arr } };//Read(s);returnArr[0].size(); // error: Out of bounds access in expression 'Arr[0]' because 'Arr' is empty.
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The code below results in a containerOutOfBounds warning with v2.3, The idea is that Read() would fill the vector via pointer. It seems that cppcheck loses track of the pointer when more than one set of braces is involved.
Maybe this is related: https://trac.cppcheck.net/ticket/10037
Do I need to edit the code? I do not see the error Out of bounds access in expression 'Arr[0]' because 'Arr' is empty.
Sorry, I posted the version that doesn't give the warning.
Please comment out the "this is fine" block and uncomment the blocks below.
Last edit: CHR 2020-12-17
Sorry.. can you show the exact code.. I do not see the error with this neither:
Are
#include <string> #include <vector>
available? I can't check it right now, will report back tomorrow.Did you use
--inconclusive
?I modified the example to show the difference more clearly:
Output:
aha.. no I did not use --inconclusive.. I will check that..
Were you able to reproduce it?
Thanks for reminding me! I can reproduce now and created this ticket: https://trac.cppcheck.net/ticket/10076
I get syntax error for t2 so I left that out. for t there is no fp so I left that out also. but for s there is a false positive in deed.
Awesome, thanks!
Maybe the example involving t2 only compiles with MSVC? But I don't think it's important.
Last edit: CHR 2021-01-05