Merge pull request #199 from simartin/ticket_5168
Ticket #5168: Don't crash when simplifying bit-fields for invalid code.
This commit is contained in:
commit
8b77b7711c
|
@ -9580,7 +9580,7 @@ void Tokenizer::simplifyBitfields()
|
||||||
tok->next()->str() != "default") {
|
tok->next()->str() != "default") {
|
||||||
const bool offset = (tok->next()->str() == "const");
|
const bool offset = (tok->next()->str() == "const");
|
||||||
|
|
||||||
if (!Token::Match(tok->tokAt(3 + (offset ? 1 : 0)), "[{};]")) {
|
if (!Token::Match(tok->tokAt(3 + (offset ? 1 : 0)), "[{};()]")) {
|
||||||
tok->deleteNext(4 + (offset ? 1 : 0));
|
tok->deleteNext(4 + (offset ? 1 : 0));
|
||||||
goback = true;
|
goback = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ private:
|
||||||
TEST_CASE(garbageCode2); // #4300
|
TEST_CASE(garbageCode2); // #4300
|
||||||
TEST_CASE(garbageCode3); // #4869
|
TEST_CASE(garbageCode3); // #4869
|
||||||
TEST_CASE(garbageCode4); // #4887
|
TEST_CASE(garbageCode4); // #4887
|
||||||
|
TEST_CASE(garbageCode5); // #5168
|
||||||
|
|
||||||
TEST_CASE(simplifyFileAndLineMacro); // tokenize "return - __LINE__;"
|
TEST_CASE(simplifyFileAndLineMacro); // tokenize "return - __LINE__;"
|
||||||
|
|
||||||
|
@ -976,6 +977,10 @@ private:
|
||||||
tokenizeAndStringify("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }");
|
tokenizeAndStringify("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void garbageCode5() { // #5168
|
||||||
|
tokenizeAndStringify("( asm : ; void : );");
|
||||||
|
}
|
||||||
|
|
||||||
void simplifyFileAndLineMacro() { // tokenize 'return - __LINE__' correctly
|
void simplifyFileAndLineMacro() { // tokenize 'return - __LINE__' correctly
|
||||||
ASSERT_EQUALS("\"test.cpp\"", tokenizeAndStringify("__FILE__"));
|
ASSERT_EQUALS("\"test.cpp\"", tokenizeAndStringify("__FILE__"));
|
||||||
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
|
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
|
||||||
|
|
Loading…
Reference in New Issue