Fixed #7775 (crash at valueFlowSetConstantValue)
This commit is contained in:
parent
08a618c476
commit
4216b26b8c
@ -636,13 +636,15 @@ static Token * valueFlowSetConstantValue(const Token *tok, const Settings *setti
|
|||||||
setTokenValue(const_cast<Token *>(tok->next()), value);
|
setTokenValue(const_cast<Token *>(tok->next()), value);
|
||||||
} else if (tok2->type() && tok2->type()->isEnumType()) {
|
} else if (tok2->type() && tok2->type()->isEnumType()) {
|
||||||
long long size = settings->sizeof_int;
|
long long size = settings->sizeof_int;
|
||||||
const Token * type = tok2->type()->classScope->enumType;
|
if (tok2->type()->classScope) {
|
||||||
if (type) {
|
const Token * type = tok2->type()->classScope->enumType;
|
||||||
size = type->str() == "char" ? 1 :
|
if (type) {
|
||||||
type->str() == "short" ? settings->sizeof_short :
|
size = type->str() == "char" ? 1 :
|
||||||
type->str() == "int" ? settings->sizeof_int :
|
type->str() == "short" ? settings->sizeof_short :
|
||||||
(type->str() == "long" && type->isLong()) ? settings->sizeof_long_long :
|
type->str() == "int" ? settings->sizeof_int :
|
||||||
type->str() == "long" ? settings->sizeof_long : 0;
|
(type->str() == "long" && type->isLong()) ? settings->sizeof_long_long :
|
||||||
|
type->str() == "long" ? settings->sizeof_long : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ValueFlow::Value value(size);
|
ValueFlow::Value value(size);
|
||||||
value.setKnown();
|
value.setKnown();
|
||||||
|
@ -77,6 +77,8 @@ private:
|
|||||||
TEST_CASE(valueFlowFunctionDefaultParameter);
|
TEST_CASE(valueFlowFunctionDefaultParameter);
|
||||||
|
|
||||||
TEST_CASE(knownValue);
|
TEST_CASE(knownValue);
|
||||||
|
|
||||||
|
TEST_CASE(valueFlowSizeofForwardDeclaredEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testValueOfX(const char code[], unsigned int linenr, int value) {
|
bool testValueOfX(const char code[], unsigned int linenr, int value) {
|
||||||
@ -2011,6 +2013,11 @@ private:
|
|||||||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 7));
|
ASSERT_EQUALS(false, testValueOfX(code, 4U, 7));
|
||||||
ASSERT(value.isKnown());
|
ASSERT(value.isKnown());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void valueFlowSizeofForwardDeclaredEnum() {
|
||||||
|
const char *code = "enum E; sz=sizeof(E);";
|
||||||
|
valueOfTok(code, "="); // Don't crash (#7775)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestValueFlow)
|
REGISTER_TEST(TestValueFlow)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user