From 25b1f2f54119bd5f394680272c6ff2a7706e92ab Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 10 Apr 2014 19:45:24 +0200 Subject: [PATCH] Fixed #5643 (crash on address-of-operator& in condition) as suggested by serval2412 --- lib/checkassignif.cpp | 2 ++ test/testassignif.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/checkassignif.cpp b/lib/checkassignif.cpp index c5c20ec74..5ff39b5d7 100644 --- a/lib/checkassignif.cpp +++ b/lib/checkassignif.cpp @@ -264,6 +264,8 @@ static bool isOverlappingCond(const Token * const cond1, const Token * const con if (cond1->str() == "&" && cond1->astOperand1() && cond2->astOperand2()) { const Token *expr1 = cond1->astOperand1(); const Token *num1 = cond1->astOperand2(); + if (!num1) // unary operator& + return false; if (!num1->isNumber()) std::swap(expr1,num1); if (!num1->isNumber() || MathLib::isNegative(num1->str())) diff --git a/test/testassignif.cpp b/test/testassignif.cpp index f98ba22e4..dbb4d5a0c 100644 --- a/test/testassignif.cpp +++ b/test/testassignif.cpp @@ -218,6 +218,13 @@ private: " if (y==1) {}\n" "}"); ASSERT_EQUALS("", errout.str()); + + // no crash on unary operator& (#5643) + check("SdrObject* ApplyGraphicToObject() {\n" + " if (&rHitObject) {}\n" + " else if (rHitObject.IsClosedObj() && !&rHitObject) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void mismatchingBitAnd() {