diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 01cc1abc3..b944423d7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1970,7 +1970,7 @@ void Tokenizer::concatenateNegativeNumberAndAnyPositive() if (!Token::Match(tok, "?|:|,|(|[|{|return|case|sizeof|%op% +|-") || tok->tokType() == Token::eIncDecOp) continue; - while (tok->next()->str() == "+") + while (tok->next() && tok->next()->str() == "+") tok->deleteNext(); if (Token::Match(tok->next(), "- %num%")) { diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 99adeacb1..1d62a053d 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -163,6 +163,7 @@ private: TEST_CASE(garbageCode121); // #2585 TEST_CASE(garbageCode122); // #6303 TEST_CASE(garbageCode123); + TEST_CASE(garbageCode124); // 6948 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -933,6 +934,10 @@ private: "}"); } + void garbageCode124() { + checkCode("+---+"); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"