diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 24eea8508..74427ae1f 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1066,7 +1066,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() { // check string literals for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { - if (Token::Match(tok, "%str% [")) { + if (Token::Match(tok, "%str% [") && tok->next()->astOperand2()) { const std::size_t strLen = Token::getStrLength(tok); const ValueFlow::Value *value = tok->next()->astOperand2()->getMaxValue(false); if (value && value->intvalue > strLen) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index d6f3a56d2..f8c312fd1 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -202,6 +202,7 @@ private: TEST_CASE(garbageCode151); // #4175 TEST_CASE(garbageCode152); // travis after 9c7271a5 TEST_CASE(garbageCode153); + TEST_CASE(garbageCode154); // #7112 TEST_CASE(garbageValueFlow); @@ -1218,6 +1219,10 @@ private: ASSERT_THROW(checkCode("enum { X = << { X } } { X X } enum { X = << { ( X ) } } { } X */"), InternalError); } + void garbageCode154() { + checkCode("\"abc\"[];"); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"