I found a piece of c++ code which was obviously incorrect, and I thought that it could be an idea for a new checker:
std::vector<...> v;
...
if (v.size() > v.capacity()) {
...
}
The 'if' condition is always false since v.size() can never be bigger than v.capacity(). So the code is incorrect. The code was actually meant to do...
if (v.capacity() > v.size()) {
...
}
cppcheck could probably warn about such a condition which is always false (size of vector never exceeds capacity). gcc or clang do not warn about this. Latest cppcheck in git does not warn about it either.
PS: I wanted to open a trac ticket about this, but I forgot my password and I see no way of requesting a new password.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can give you a new password. what username do you have?
I'm replying very late. I'm fine after all, if reporting suggestions for cppcheck
is allowed in the forum. I did not see any comments about the possible
improvement reported in this thread.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found a piece of c++ code which was obviously incorrect, and I thought that it could be an idea for a new checker:
std::vector<...> v;
...
if (v.size() > v.capacity()) {
...
}
The 'if' condition is always false since v.size() can never be bigger than v.capacity(). So the code is incorrect. The code was actually meant to do...
if (v.capacity() > v.size()) {
...
}
cppcheck could probably warn about such a condition which is always false (size of vector never exceeds capacity). gcc or clang do not warn about this. Latest cppcheck in git does not warn about it either.
PS: I wanted to open a trac ticket about this, but I forgot my password and I see no way of requesting a new password.
I can give you a new password. what username do you have?
I'm replying very late. I'm fine after all, if reporting suggestions for cppcheck
is allowed in the forum. I did not see any comments about the possible
improvement reported in this thread.
It is allowed, but it is very likely that the information gets lost if it is not in the bugtracker.