diff --git a/lib/checkassignif.cpp b/lib/checkassignif.cpp index 8a3df6679..33f012a9a 100644 --- a/lib/checkassignif.cpp +++ b/lib/checkassignif.cpp @@ -55,7 +55,7 @@ void CheckAssignIf::assignIf() const Token *endToken = Token::findsimplematch(tok, ";"); // Casting address - if (Token::Match(endToken->tokAt(-4), "* ) & %any% ;")) + if (endToken && Token::Match(endToken->tokAt(-4), "* ) & %any% ;")) endToken = nullptr; if (endToken && Token::Match(endToken->tokAt(-2), "[&|] %num% ;")) { diff --git a/test/testassignif.cpp b/test/testassignif.cpp index f7d0443bc..418466904 100644 --- a/test/testassignif.cpp +++ b/test/testassignif.cpp @@ -38,6 +38,7 @@ private: TEST_CASE(compare); // mismatching LHS/RHS in comparison TEST_CASE(multicompare); // mismatching comparisons TEST_CASE(duplicateIf); // duplicate conditions in if and else-if + TEST_CASE(invalidMissingSemicolon); // crash as of #5867 } void check(const char code[]) { @@ -378,6 +379,15 @@ private: "}"); ASSERT_EQUALS("", errout.str()); } + + void invalidMissingSemicolon() + { + // simply survive - a syntax error would be even better + check("void f(int x) {\n" + " x = 42\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestAssignIf)