From 636bf75799daf68b1ad418ea371f5a996ce896f5 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 26 Oct 2015 13:29:47 +0100 Subject: [PATCH] Fixed crash on garbage code (#7074) --- lib/token.cpp | 2 +- test/testgarbage.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/token.cpp b/lib/token.cpp index d63f04b3d..a5f028f88 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1158,7 +1158,7 @@ bool Token::isUnaryPreOp() const return true; const Token *tokbefore = _previous; const Token *tokafter = _next; - for (int distance = 1; distance < 10; distance++) { + for (int distance = 1; distance < 10 && tokbefore; distance++) { if (tokbefore == _astOperand1) return false; if (tokafter == _astOperand1) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index baa1890b0..a7787086d 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -193,6 +193,7 @@ private: TEST_CASE(garbageCode142); // #7050 TEST_CASE(garbageCode143); // #6922 TEST_CASE(garbageCode144); // #6865 + TEST_CASE(garbageCode145); // #7074 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -1138,6 +1139,10 @@ private: //ASSERT_THROW(checkCode("template < typename > struct A { } ; template < typename > struct A < INVALID > : A < int[ > { }] ;"), InternalError); } + void garbageCode145() { // #7074 + checkCode("++4++ + + E++++++++++ + ch " "tp.oed5[.]"); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"