Skip to content

Commit f70a8b2

Browse files
Update checkbufferoverrun.cpp
1 parent fec0f8d commit f70a8b2

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/checkbufferoverrun.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,14 @@ ValueFlow::Value CheckBufferOverrunImpl::getBufferSize(const Token *bufTok) cons
558558
return ValueFlow::Value(-1);
559559
if (bufTok->isUnaryOp("&"))
560560
bufTok = bufTok->astOperand1();
561-
const Variable *var = bufTok->variable();
561+
const Token* varTok = bufTok;
562+
if (Token::simpleMatch(bufTok, "[")) {
563+
const Token* index = bufTok->astOperand2();
564+
if (!(index && index->hasKnownIntValue() && index->getKnownIntValue() == 0))
565+
return ValueFlow::Value(-1);
566+
varTok = varTok->astOperand1();
567+
}
568+
const Variable *var = varTok->variable();
562569

563570
if (!var || var->dimensions().empty()) {
564571
const ValueFlow::Value *value = getBufferSizeValue(bufTok);

0 commit comments

Comments
 (0)