#8079 SymbolDatabase::createSymbolDatabaseEnums() crashes on invalid enum declaration
This commit is contained in:
parent
1dd42d9a9e
commit
45ba1ff1e3
|
@ -1341,6 +1341,8 @@ void SymbolDatabase::createSymbolDatabaseEnums()
|
|||
|
||||
// look for initialization tokens that can be converted to enumerators and convert them
|
||||
if (enumerator.start) {
|
||||
if (!enumerator.end)
|
||||
_tokenizer->syntaxError(enumerator.start);
|
||||
for (const Token * tok3 = enumerator.start; tok3 && tok3 != enumerator.end->next(); tok3 = tok3->next()) {
|
||||
if (tok3->tokType() == Token::eName) {
|
||||
const Enumerator * e = findEnumerator(tok3);
|
||||
|
@ -1350,19 +1352,17 @@ void SymbolDatabase::createSymbolDatabaseEnums()
|
|||
}
|
||||
|
||||
// look for possible constant folding expressions
|
||||
if (enumerator.start) {
|
||||
// rhs of operator:
|
||||
const Token *rhs = enumerator.start->previous()->astOperand2();
|
||||
// rhs of operator:
|
||||
const Token *rhs = enumerator.start->previous()->astOperand2();
|
||||
|
||||
// constant folding of expression:
|
||||
ValueFlow::valueFlowConstantFoldAST(rhs, _settings);
|
||||
// constant folding of expression:
|
||||
ValueFlow::valueFlowConstantFoldAST(rhs, _settings);
|
||||
|
||||
// get constant folded value:
|
||||
if (rhs && rhs->values().size() == 1U && rhs->values().front().isKnown()) {
|
||||
enumerator.value = rhs->values().front().intvalue;
|
||||
enumerator.value_known = true;
|
||||
value = enumerator.value + 1;
|
||||
}
|
||||
// get constant folded value:
|
||||
if (rhs && rhs->values().size() == 1U && rhs->values().front().isKnown()) {
|
||||
enumerator.value = rhs->values().front().intvalue;
|
||||
enumerator.value_known = true;
|
||||
value = enumerator.value + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -219,6 +219,7 @@ private:
|
|||
TEST_CASE(templateSimplifierCrashes);
|
||||
TEST_CASE(syntaxErrorFirstToken); // Make sure syntax errors are detected and reported
|
||||
TEST_CASE(syntaxErrorLastToken); // Make sure syntax errors are detected and reported
|
||||
TEST_CASE(enumTrailingComma);
|
||||
}
|
||||
|
||||
std::string checkCode(const char code[], bool cpp = true) {
|
||||
|
@ -1466,6 +1467,10 @@ private:
|
|||
|
||||
// ASSERT_THROW( , InternalError)
|
||||
}
|
||||
|
||||
void enumTrailingComma() {
|
||||
ASSERT_THROW(checkCode("enum ssl_shutdown_t {ssl_shutdown_none = 0,ssl_shutdown_close_notify = , } ;"), InternalError); // #8079
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestGarbage)
|
||||
|
|
Loading…
Reference in New Issue