Token::hasKnownIntValue: Fix when there is one possible int value and one known BUFFER_SIZE value, it should return false.

This commit is contained in:
Daniel Marjamäki 2019-07-27 08:25:07 +02:00
parent 22f8080d1d
commit 1c75257212
2 changed files with 24 additions and 1 deletions

View File

@ -936,7 +936,13 @@ public:
}
bool hasKnownIntValue() const {
return hasKnownValue() && std::any_of(mImpl->mValues->begin(), mImpl->mValues->end(), std::mem_fn(&ValueFlow::Value::isIntValue));
if (!mImpl->mValues)
return false;
for (const ValueFlow::Value &value : *mImpl->mValues) {
if (value.isKnown() && value.isIntValue())
return true;
}
return false;
}
bool hasKnownValue() const {

View File

@ -106,6 +106,8 @@ private:
TEST_CASE(findClosingBracket);
TEST_CASE(expressionString);
TEST_CASE(hasKnownIntValue);
}
void nextprevious() const {
@ -989,6 +991,21 @@ private:
givenACodeSampleToTokenize data4("return L\"a\";");
ASSERT_EQUALS("returnL\"a\"", data4.tokens()->expressionString());
}
void hasKnownIntValue() {
// pointer might be NULL
ValueFlow::Value v1(0);
// pointer points at buffer that is 2 bytes
ValueFlow::Value v2(2);
v2.valueType = ValueFlow::Value::BUFFER_SIZE;
v2.setKnown();
Token token;
ASSERT_EQUALS(true, token.addValue(v1));
ASSERT_EQUALS(true, token.addValue(v2));
ASSERT_EQUALS(false, token.hasKnownIntValue());
}
};
REGISTER_TEST(TestToken)