Fixed #8351 (segmentation fault on objective C code)

This commit is contained in:
Daniel Marjamäki 2018-01-24 18:06:11 +01:00
parent 6b5805041b
commit 96e387a486
2 changed files with 12 additions and 0 deletions

View File

@ -8394,6 +8394,12 @@ const Token * Tokenizer::findGarbageCode() const
} }
} }
// Objective C/C++
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "[;{}] [ %name% %name% ] ;"))
return tok->next();
}
return nullptr; return nullptr;
} }

View File

@ -76,6 +76,8 @@ private:
TEST_CASE(validate); TEST_CASE(validate);
TEST_CASE(objectiveC); // Syntax error should be written for objective C/C++ code.
TEST_CASE(syntax_case_default); TEST_CASE(syntax_case_default);
TEST_CASE(foreach); // #3690 TEST_CASE(foreach); // #3690
@ -848,6 +850,10 @@ private:
ASSERT_THROW(tokenizeAndStringify("void foo(int i) { reinterpret_cast<char>(i) };",false,false,Settings::Native,"test.h"), InternalError); ASSERT_THROW(tokenizeAndStringify("void foo(int i) { reinterpret_cast<char>(i) };",false,false,Settings::Native,"test.h"), InternalError);
} }
void objectiveC() {
ASSERT_THROW(tokenizeAndStringify("void f() { [foo bar]; }"), InternalError);
}
void syntax_case_default() { // correct syntax void syntax_case_default() { // correct syntax
tokenizeAndStringify("void f() {switch (n) { case 0: z(); break;}}"); tokenizeAndStringify("void f() {switch (n) { case 0: z(); break;}}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());