Fixed #4561 (cppcheck 1.58 crashes on empty signals block in headerfile)

This commit is contained in:
Daniel Marjamäki 2013-02-07 17:03:08 +01:00
parent ad61ed2f93
commit 463121be71
2 changed files with 7 additions and 1 deletions

View File

@ -8790,7 +8790,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 (tok->strAt(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;
} }

View File

@ -419,6 +419,7 @@ private:
TEST_CASE(bitfields11); // ticket #2845 (segmentation fault) TEST_CASE(bitfields11); // ticket #2845 (segmentation fault)
TEST_CASE(bitfields12); // ticket #3485 (segmentation fault) TEST_CASE(bitfields12); // ticket #3485 (segmentation fault)
TEST_CASE(bitfields13); // ticket #3502 (segmentation fault) TEST_CASE(bitfields13); // ticket #3502 (segmentation fault)
TEST_CASE(bitfields14); // ticket #4561 (segfault for 'class a { signals: };')
TEST_CASE(simplifyNamespaceStd); TEST_CASE(simplifyNamespaceStd);
@ -6846,6 +6847,11 @@ private:
ASSERT_EQUALS("x y ;", tokenizeAndStringify("struct{x y:};\n",false)); ASSERT_EQUALS("x y ;", tokenizeAndStringify("struct{x y:};\n",false));
} }
void bitfields14() { // #4561 - crash for 'signals:'
ASSERT_EQUALS("class x { signals : } ;", tokenizeAndStringify("class x { signals: };\n",false));
}
void simplifyNamespaceStd() { void simplifyNamespaceStd() {
static const char code1[] = "map<foo, bar> m;"; // namespace std is not used static const char code1[] = "map<foo, bar> m;"; // namespace std is not used
ASSERT_EQUALS("map < foo , bar > m ;", tokenizeAndStringify(code1, false)); ASSERT_EQUALS("map < foo , bar > m ;", tokenizeAndStringify(code1, false));