diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 713cb7941..0877a276d 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -775,7 +775,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) } if (Token::simpleMatch(tok->previous(), "* 1") || Token::simpleMatch(tok, "1 *")) { - if (tok->previous()->isOp()) + if (tok->previous() && tok->previous()->isOp()) tok = tok->previous(); tok->deleteNext(); tok->deleteThis(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 31a0b0945..96f550c82 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5900,6 +5900,8 @@ private: tokenizeAndStringify("int f(int a) { return 0 * a; }", 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)); + // ticket #3512 - Don't crash on garbage code + ASSERT_EQUALS("p = const", tokenizeAndStringify("1 *p = const", true)); } void simplifyCompoundAssignment() {