diff --git a/lib/checkother.cpp b/lib/checkother.cpp index cb6813c86..33eba962b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1435,7 +1435,7 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us } bool bFirstAssignment=false; - for (; tok != end; tok = tok->next()) { + for (; tok && tok != end; tok = tok->next()) { if (tok->str() == "goto") return false; if (tok->str() == "continue") diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index bd7bf9cd0..ca2e23cf8 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -122,6 +122,7 @@ private: TEST_CASE(garbageCode81); TEST_CASE(garbageCode82); TEST_CASE(garbageCode83); + TEST_CASE(garbageCode84); TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -676,6 +677,10 @@ private: ASSERT_THROW(checkCode("namespace A { class } class A { friend C ; } { } ;"), InternalError); } + void garbageCode84() { // #6780 + checkCode("int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { }"); // do not crash + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"