From ab1113fb164533d097cef1376f1416ccb156a317 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 22 Jul 2015 13:32:34 +0200 Subject: [PATCH] Fixed crash on garbage code #6859 --- lib/valueflow.cpp | 2 +- test/testgarbage.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9f37d37c5..435389a50 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -284,7 +284,7 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign while (parent && parent->str() == ",") parent = parent->astParent(); if (parent && parent->str() == "(") { - if (parent->astOperand1()->isName() && !parent->astOperand1()->function()) + if (parent->astOperand1() && parent->astOperand1()->isName() && !parent->astOperand1()->function()) return true; // TODO: check if function parameter is non-const reference etc.. } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 4df2edfbb..7e7390d83 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -144,6 +144,7 @@ private: TEST_CASE(garbageCode102); // #6846 TEST_CASE(garbageCode103); // #6824 TEST_CASE(garbageCode104); // #6847 + TEST_CASE(garbageCode105); // #6859 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -814,6 +815,10 @@ private: ASSERT_THROW(checkCode("template < Types > struct S {> ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) } { ( )> >} { ( ) { } } ( ) { ( ) }"), InternalError); } + void garbageCode105() { // #6859 + checkCode("void foo (int i) { int a , for (a 1; a( < 4; a++) if (a) (b b++) (b);) n++; }"); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"