From e0838ff194b8bf330025ed79efab70d2626747b6 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 21 Aug 2016 11:06:48 +0200 Subject: [PATCH] Fixed crash on garbage code (#7699) --- lib/valueflow.cpp | 2 +- test/testgarbage.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 4f882eb5d..7d4c9c903 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -362,7 +362,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &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? if (parent->astOperand1()->values.size() == 1U && parent->astOperand1()->values.front().isKnown()) { const ValueFlow::Value &condvalue = parent->astOperand1()->values.front(); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 4f7087ad9..7b2c43e47 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -232,6 +232,7 @@ private: TEST_CASE(garbageCode181); TEST_CASE(garbageCode182); // #4195 TEST_CASE(garbageCode183); // #7505 + TEST_CASE(garbageCode184); // #7699 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageAST); @@ -1521,6 +1522,13 @@ private: 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)