From 2eb849299357242c0d32b1665d5cb190de434295 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 9 Oct 2015 13:49:17 +0200 Subject: [PATCH] Fixed crash on garbage code #7034 --- lib/checkother.cpp | 2 +- test/testgarbage.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a56fb8c40..1ed3b2fe9 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1482,7 +1482,7 @@ void CheckOther::checkCharVariable() if (astIsSignedChar(index) && index->getValueGE(0x80, _settings)) charArrayIndexError(tok); } - if (Token::Match(tok, "[&|^]") && tok->astOperand2()) { + if (Token::Match(tok, "[&|^]") && tok->astOperand2() && tok->astOperand1()) { bool warn = false; if (astIsSignedChar(tok->astOperand1())) { const ValueFlow::Value *v1 = tok->astOperand1()->getValueLE(-1, _settings); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 8ef22d0d5..6c37a712c 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -186,6 +186,7 @@ private: TEST_CASE(garbageCode134); TEST_CASE(garbageCode135); // #4994 TEST_CASE(garbageCode136); // #7033 + TEST_CASE(garbageCode137); // #7034 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -1078,6 +1079,10 @@ private: checkCode("{ } () { void f() { node_t * n; for (; -n) {} } } { }"); } + void garbageCode137() { // #7034 + checkCode("\" \" typedef signed char f; \" \"; void a() { f * s = () &[]; (; ) (; ) }"); + } + void garbageValueFlow() { // #6089