Fixed #9058 (crash on invalid code in FwdAnalysis::checkRecursive)
This commit is contained in:
parent
d6b806c592
commit
a9082c902a
|
@ -8508,6 +8508,22 @@ void Tokenizer::findGarbageCode() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keyword keyword
|
||||||
|
const std::set<std::string> nonConsecutiveKeywords{"break",
|
||||||
|
"continue",
|
||||||
|
"for",
|
||||||
|
"goto",
|
||||||
|
"if",
|
||||||
|
"return",
|
||||||
|
"switch",
|
||||||
|
"throw",
|
||||||
|
"typedef",
|
||||||
|
"while"};
|
||||||
|
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
||||||
|
if (Token::Match(tok, "%name% %name%") && nonConsecutiveKeywords.count(tok->str()) == 1 && nonConsecutiveKeywords.count(tok->next()->str()) == 1)
|
||||||
|
syntaxError(tok);
|
||||||
|
}
|
||||||
|
|
||||||
// case keyword must be inside switch
|
// case keyword must be inside switch
|
||||||
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
||||||
if (Token::simpleMatch(tok, "switch (")) {
|
if (Token::simpleMatch(tok, "switch (")) {
|
||||||
|
|
|
@ -244,6 +244,7 @@ private:
|
||||||
TEST_CASE(syntaxErrorFirstToken); // Make sure syntax errors are detected and reported
|
TEST_CASE(syntaxErrorFirstToken); // Make sure syntax errors are detected and reported
|
||||||
TEST_CASE(syntaxErrorLastToken); // Make sure syntax errors are detected and reported
|
TEST_CASE(syntaxErrorLastToken); // Make sure syntax errors are detected and reported
|
||||||
TEST_CASE(syntaxErrorCase);
|
TEST_CASE(syntaxErrorCase);
|
||||||
|
TEST_CASE(syntaxErrorFuzzerCliType1);
|
||||||
TEST_CASE(enumTrailingComma);
|
TEST_CASE(enumTrailingComma);
|
||||||
|
|
||||||
TEST_CASE(nonGarbageCode1); // #8346
|
TEST_CASE(nonGarbageCode1); // #8346
|
||||||
|
@ -339,8 +340,8 @@ private:
|
||||||
tokenizer.tokenize(istr, "test.cpp");
|
tokenizer.tokenize(istr, "test.cpp");
|
||||||
assertThrowFail(__FILE__, __LINE__);
|
assertThrowFail(__FILE__, __LINE__);
|
||||||
} catch (InternalError& e) {
|
} catch (InternalError& e) {
|
||||||
ASSERT_EQUALS("Analysis failed. If the code is valid then please report this failure.", e.errorMessage);
|
ASSERT_EQUALS("syntax error", e.errorMessage);
|
||||||
ASSERT_EQUALS("cppcheckError", e.id);
|
ASSERT_EQUALS("syntaxError", e.id);
|
||||||
ASSERT_EQUALS(4, e.token->linenr());
|
ASSERT_EQUALS(4, e.token->linenr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,7 +434,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode7() {
|
void garbageCode7() {
|
||||||
checkCode("1 (int j) { return return (c) * sizeof } y[1];");
|
ASSERT_THROW(checkCode("1 (int j) { return return (c) * sizeof } y[1];"), InternalError);
|
||||||
ASSERT_THROW(checkCode("foo(Args&&...) fn void = { } auto template<typename... bar(Args&&...)"), InternalError);
|
ASSERT_THROW(checkCode("foo(Args&&...) fn void = { } auto template<typename... bar(Args&&...)"), InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1651,6 +1652,10 @@ private:
|
||||||
ASSERT_THROW(checkCode("void f() { 1 \"\"; }"), InternalError);
|
ASSERT_THROW(checkCode("void f() { 1 \"\"; }"), InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void syntaxErrorFuzzerCliType1() {
|
||||||
|
ASSERT_THROW(checkCode("void f(){x=0,return return''[]()}"), InternalError);
|
||||||
|
}
|
||||||
|
|
||||||
void enumTrailingComma() {
|
void enumTrailingComma() {
|
||||||
ASSERT_THROW(checkCode("enum ssl_shutdown_t {ssl_shutdown_none = 0,ssl_shutdown_close_notify = , } ;"), InternalError); // #8079
|
ASSERT_THROW(checkCode("enum ssl_shutdown_t {ssl_shutdown_none = 0,ssl_shutdown_close_notify = , } ;"), InternalError); // #8079
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue