-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue 9979: false positive: containerOutOfBounds with conditional resize #3136
Fix issue 9979: false positive: containerOutOfBounds with conditional resize #3136
Conversation
lib/token.cpp
Outdated
@@ -29,6 +29,7 @@ | |||
#include <algorithm> | |||
#include <cassert> | |||
#include <cctype> | |||
#include <cstdio> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems my editor sometimes insert these headers. I'll remove them.
I see this error on travis:
What does that mean? Also the scriptcheck stage fails, but there is no errors in the output. |
is there unsigned integer overflow or a weird looking shift operation (that would overflow without integer promotion). |
No I check that before doing a bitshift calculation here. |
hmm.. I try.. |
Example code:
debug output before your changes:
debug output after your changes:
Spontanously it seems to me those values should be known? |
The addons did not handle impossible values very nicely. I made a tweak for that with 22727ee |
They're not set since it can't be stored as To avoid confusion, I skip setting a value if its negative and unsigned unless its an impossible value. If we move to making |
Ok with that fix it still errors with this:
I assume there is some misra tests I need to disable. Or perhaps there is some better logic to use to allow for negative values, but I am not sure how. |
Ideally the value of the |
well we could disable those but then we have regressions. It should be detected that |
I see, this is a 32-bit unsigned integer. This should be fine since we truncate the value, I just need to check the size of the type. Although, it will still be somewhat ambigious with Of course, this wont fix the issue with |
The misra addon needs to be rewritten a bit also. It does not check for overflows properly. If you fix the
yes. @IOBYTE had such work in progress. how is the progress on that? did that work in windows also or was it only for gcc? I am guessing that it is not necessary to use 128-bit integers we could use 64 bits for the integer data and then add a flag or something that indicates the sign. I don't know if we could encapsulate such 64 bit value somehow.. so it will be somewhat straightforward to use. For instance if it has internal knowledge about ValueType it could ensure that the value is truncated according to the type and perform the proper integer operations. |
I had it working with gcc. I tried a few 128 bit libraries but they all had issues. Some of the removal of bigint patches were merged but bigint is still being used everywhere inappropriately. This is on hold because I'm trying to get simplifyUsing stable for release. |
I think we should disable the check because it is not implemented properly. And then we should implement the check properly. So I believe you can ignore that particular problem. |
We could build a simple wrapper class that has: struct bigint {
biguint data;
int8_t sign; // Either 1 or -1
}; Implementing the arithmetic operators should be simpler than implementing large integer math. The only thing is that this won't use twos complement. |
What were some of the issues? I wonder if we need to write a wrapper around these classes. |
It still fails in the CI. |
yes exactly. Unless the 128-bit integer works well I think that is a good solution.. |
Example code:
with HEAD Cppcheck says the value is a large positive value both in the debug output and dump output. After your changes this value is removed. This particular behavior is unfortunate we have the proper behavior in HEAD as far as I see but not after your changes.. |
You could add a TODO in the misra-test.c on the corresponding line.
When the ValueFlow is fixed later the verification would fail on this line and then we can remove the TODO. |
So sciptcheck fails, but there is no error message. |
maybe some test problem.. I restarted that test. |
From what I see the Makefile should be re-generated and updated. |
lib/token.cpp
Outdated
{ | ||
if (x.bound != ValueFlow::Value::Bound::Point && x.bound == y.bound) { | ||
return true; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This else is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
It looks like this passes the CI now. |
No description provided.