Fixed ticket #3512 (segmentation fault of cppcheck ( 1 *p = const))

This commit is contained in:
Edoardo Prezioso 2012-01-14 00:43:58 +01:00
parent 37f3aa1528
commit 6a248c35b5
2 changed files with 3 additions and 1 deletions

View File

@ -775,7 +775,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
} }
if (Token::simpleMatch(tok->previous(), "* 1") || Token::simpleMatch(tok, "1 *")) { if (Token::simpleMatch(tok->previous(), "* 1") || Token::simpleMatch(tok, "1 *")) {
if (tok->previous()->isOp()) if (tok->previous() && tok->previous()->isOp())
tok = tok->previous(); tok = tok->previous();
tok->deleteNext(); tok->deleteNext();
tok->deleteThis(); tok->deleteThis();

View File

@ -5900,6 +5900,8 @@ private:
tokenizeAndStringify("int f(int a) { return 0 * a; }", true)); tokenizeAndStringify("int f(int a) { return 0 * a; }", true));
ASSERT_EQUALS("bool f ( int i ) { switch ( i ) { case 15 : ; return true ; } }", ASSERT_EQUALS("bool f ( int i ) { switch ( i ) { case 15 : ; return true ; } }",
tokenizeAndStringify("bool f(int i) { switch (i) { case 10 + 5: return true; } }", true)); tokenizeAndStringify("bool f(int i) { switch (i) { case 10 + 5: return true; } }", true));
// ticket #3512 - Don't crash on garbage code
ASSERT_EQUALS("p = const", tokenizeAndStringify("1 *p = const", true));
} }
void simplifyCompoundAssignment() { void simplifyCompoundAssignment() {