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);
|
||||
} else if (tok2->type() && tok2->type()->isEnumType()) {
|
||||
long long size = settings->sizeof_int;
|
||||
const Token * type = tok2->type()->classScope->enumType;
|
||||
if (type) {
|
||||
size = type->str() == "char" ? 1 :
|
||||
type->str() == "short" ? settings->sizeof_short :
|
||||
type->str() == "int" ? settings->sizeof_int :
|
||||
(type->str() == "long" && type->isLong()) ? settings->sizeof_long_long :
|
||||
type->str() == "long" ? settings->sizeof_long : 0;
|
||||
if (tok2->type()->classScope) {
|
||||
const Token * type = tok2->type()->classScope->enumType;
|
||||
if (type) {
|
||||
size = type->str() == "char" ? 1 :
|
||||
type->str() == "short" ? settings->sizeof_short :
|
||||
type->str() == "int" ? settings->sizeof_int :
|
||||
(type->str() == "long" && type->isLong()) ? settings->sizeof_long_long :
|
||||
type->str() == "long" ? settings->sizeof_long : 0;
|
||||
}
|
||||
}
|
||||
ValueFlow::Value value(size);
|
||||
value.setKnown();
|
||||
|
|
|
@ -77,6 +77,8 @@ private:
|
|||
TEST_CASE(valueFlowFunctionDefaultParameter);
|
||||
|
||||
TEST_CASE(knownValue);
|
||||
|
||||
TEST_CASE(valueFlowSizeofForwardDeclaredEnum);
|
||||
}
|
||||
|
||||
bool testValueOfX(const char code[], unsigned int linenr, int value) {
|
||||
|
@ -2011,6 +2013,11 @@ private:
|
|||
ASSERT_EQUALS(false, testValueOfX(code, 4U, 7));
|
||||
ASSERT(value.isKnown());
|
||||
}
|
||||
|
||||
void valueFlowSizeofForwardDeclaredEnum() {
|
||||
const char *code = "enum E; sz=sizeof(E);";
|
||||
valueOfTok(code, "="); // Don't crash (#7775)
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestValueFlow)
|
||||
|
|
Loading…
Reference in New Issue