Fixed crash on garbage code (#7699)

This commit is contained in:
PKEuS 2016-08-21 11:06:48 +02:00
parent d982dc5ffe
commit e0838ff194
2 changed files with 9 additions and 1 deletions

View File

@ -362,7 +362,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value)
setTokenValue(parent,value); setTokenValue(parent,value);
} }
else if (parent->str() == "?" && tok->str() == ":" && tok == parent->astOperand2()) { else if (parent->str() == "?" && tok->str() == ":" && tok == parent->astOperand2() && parent->astOperand1()) {
// is condition always true/false? // is condition always true/false?
if (parent->astOperand1()->values.size() == 1U && parent->astOperand1()->values.front().isKnown()) { if (parent->astOperand1()->values.size() == 1U && parent->astOperand1()->values.front().isKnown()) {
const ValueFlow::Value &condvalue = parent->astOperand1()->values.front(); const ValueFlow::Value &condvalue = parent->astOperand1()->values.front();

View File

@ -232,6 +232,7 @@ private:
TEST_CASE(garbageCode181); TEST_CASE(garbageCode181);
TEST_CASE(garbageCode182); // #4195 TEST_CASE(garbageCode182); // #4195
TEST_CASE(garbageCode183); // #7505 TEST_CASE(garbageCode183); // #7505
TEST_CASE(garbageCode184); // #7699
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST); TEST_CASE(garbageAST);
@ -1521,6 +1522,13 @@ private:
ASSERT_THROW(checkCode("= { int } enum return { r = f() f(); }"), InternalError); ASSERT_THROW(checkCode("= { int } enum return { r = f() f(); }"), InternalError);
} }
void garbageCode184() { // #7699
checkCode("unsigned int AquaSalSystem::GetDisplayScreenCount() {\n"
" NSArray* pScreens = [NSScreen screens];\n"
" return pScreens ? [pScreens count] : 1;\n"
"}");
}
}; };
REGISTER_TEST(TestGarbage) REGISTER_TEST(TestGarbage)