Fixed #3502 (segmentation fault of cppcheck (struct{x y:};))

This commit is contained in:
Daniel Marjamäki 2012-01-23 07:39:31 +01:00
parent e39b70c1be
commit 9eb1a5864b
2 changed files with 9 additions and 1 deletions

View File

@ -8580,8 +8580,11 @@ void Tokenizer::simplifyBitfields()
if (tok1 && tok1->tokAt(2) && if (tok1 && tok1->tokAt(2) &&
(tok1->tokAt(2)->isBoolean() || Token::Match(tok1->tokAt(2), "%num%") || (tok1->tokAt(2)->isBoolean() || Token::Match(tok1->tokAt(2), "%num%") ||
!Token::Match(tok1->tokAt(2), "public|protected|private| %type% ::|<|,|{|;"))) { !Token::Match(tok1->tokAt(2), "public|protected|private| %type% ::|<|,|{|;"))) {
while (tok1->next() && !Token::Match(tok1->next(), ";|,")) while (tok1->next() && !Token::Match(tok1->next(), "[;,)]{}]")) {
if (Token::Match(tok1->next(), "[([]"))
Token::eraseTokens(tok1, tok1->next()->link());
tok1->deleteNext(); tok1->deleteNext();
}
last = tok1->next(); last = tok1->next();
} }

View File

@ -344,6 +344,7 @@ private:
TEST_CASE(bitfields10); TEST_CASE(bitfields10);
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(microsoftMFC); TEST_CASE(microsoftMFC);
TEST_CASE(microsoftMemory); TEST_CASE(microsoftMemory);
@ -5707,6 +5708,10 @@ private:
ASSERT_EQUALS("{ } ;", tokenizeAndStringify(code,false)); ASSERT_EQUALS("{ } ;", tokenizeAndStringify(code,false));
} }
void bitfields13() { // ticket #3502 (segmentation fault)
ASSERT_EQUALS("x y ;", tokenizeAndStringify("struct{x y:};\n",false));
}
void microsoftMFC() { void microsoftMFC() {
const char code1[] = "class MyDialog : public CDialog { DECLARE_MESSAGE_MAP() private: CString text; };"; const char code1[] = "class MyDialog : public CDialog { DECLARE_MESSAGE_MAP() private: CString text; };";
ASSERT_EQUALS("class MyDialog : public CDialog { private: CString text ; } ;", tokenizeAndStringify(code1,false,true,Settings::Win32A)); ASSERT_EQUALS("class MyDialog : public CDialog { private: CString text ; } ;", tokenizeAndStringify(code1,false,true,Settings::Win32A));