#5875 clang ubsan errors: lib/checkassignif.cpp:58:34: runtime error: member call on null pointer of type 'Token'

This commit is contained in:
amai 2014-05-31 15:12:04 +02:00
parent 66ad3c97b9
commit 98ea1397b3
2 changed files with 11 additions and 1 deletions

View File

@ -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% ;")) {

View File

@ -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)