Fixed ticket #3485 (segmentation fault of cppcheck ( {a:1;}; ))

This commit is contained in:
Edoardo Prezioso 2012-01-09 16:24:11 +01:00
parent 54f54761b4
commit 2dd53ec966
2 changed files with 13 additions and 1 deletions

View File

@ -8950,7 +8950,13 @@ void Tokenizer::simplifyAsm()
// Simplify bitfields // Simplify bitfields
void Tokenizer::simplifyBitfields() void Tokenizer::simplifyBitfields()
{ {
bool goback = false;
for (Token *tok = _tokens; tok; tok = tok->next()) { for (Token *tok = _tokens; tok; tok = tok->next()) {
if (goback) {
goback = false;
tok = tok->previous();
}
Token *last = 0; Token *last = 0;
if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% :") && if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% :") &&
@ -8971,7 +8977,7 @@ void Tokenizer::simplifyBitfields()
if (tok->strAt(3 + offset) != "{") { if (tok->strAt(3 + offset) != "{") {
tok->deleteNext(4+offset); tok->deleteNext(4+offset);
tok = tok->previous(); goback = true;
} }
} }

View File

@ -342,6 +342,7 @@ private:
TEST_CASE(bitfields9); // ticket #2706 TEST_CASE(bitfields9); // ticket #2706
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(microsoftMFC); TEST_CASE(microsoftMFC);
TEST_CASE(microsoftMemory); TEST_CASE(microsoftMemory);
@ -5691,6 +5692,11 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void bitfields12() { // ticket #3485 (segmentation fault)
const char code[] = "{a:1;};\n";
ASSERT_EQUALS("{ } ;", tokenizeAndStringify(code,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));