-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #13812 value potentially truncated in ValueFlowAnalyzer::evaluteInt() #8482
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -676,7 +676,7 @@ struct ValueFlowAnalyzer : Analyzer { | |
| std::vector<MathLib::bigint> evaluateInt(const Token* tok, F getProgramMemory) const | ||
| { | ||
| if (const ValueFlow::Value* v = tok->getKnownValue(ValueFlow::Value::ValueType::INT)) | ||
| return {static_cast<int>(v->intvalue)}; | ||
| return {v->intvalue}; | ||
| std::vector<MathLib::bigint> result; | ||
| ProgramMemory pm = getProgramMemory(); | ||
| if (Token::Match(tok, "&&|%oror%")) { | ||
|
|
@@ -717,7 +717,7 @@ struct ValueFlowAnalyzer : Analyzer { | |
| ProgramMemory pm = pms.get(tok, ctx, getProgramState()); | ||
| MathLib::bigint out = 0; | ||
| if (pm.getContainerEmptyValue(tok->exprId(), out)) | ||
| return {static_cast<int>(out)}; | ||
| return {out}; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harmless but unnecessary ( |
||
| return {}; | ||
| } | ||
| return {}; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -320,7 +320,7 @@ class TestValueFlow : public TestFixture { | |
| } | ||
|
|
||
| #define testValueOfX(...) testValueOfX_(__FILE__, __LINE__, __VA_ARGS__) | ||
| bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, int value, const Settings *s = nullptr) { | ||
| bool testValueOfX_(const char* file, int line, const char code[], unsigned int linenr, MathLib::bigint value, const Settings *s = nullptr) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This smells like it should have been reported by one of the compiler warnings we have disabled...
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, but so far all tests used only values in the int range.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comparison between |
||
| const Settings *settings1 = s ? s : &settings; | ||
|
|
||
| // Tokenize.. | ||
|
|
@@ -3973,6 +3973,14 @@ class TestValueFlow : public TestFixture { | |
| " return x;\n" | ||
| "}"; | ||
| ASSERT_EQUALS(true, testValueOfX(code, 4U, 246)); | ||
|
|
||
| code = "int64_t f() {\n" | ||
| " const int64_t val = 1LL << 33;\n" | ||
| " int64_t x = val;\n" | ||
| " x += val;\n" | ||
| " return x;\n" | ||
| "}"; | ||
| ASSERT_EQUALS(true, testValueOfX(code, 5U, 1LL << 34)); | ||
| } | ||
|
|
||
| void valueFlowForwardCorrelatedVariables() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.