Skip to content

Commit

Permalink
CheckBufferOverrun: bail out early in getBufferSize()
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Dec 25, 2024
1 parent e427162 commit 60dd27d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ ValueFlow::Value CheckBufferOverrun::getBufferSize(const Token *bufTok) const
if (!var)
return ValueFlow::Value(-1);

if (var->isPointer())
return ValueFlow::Value(-1);

const MathLib::bigint dim = std::accumulate(var->dimensions().cbegin(), var->dimensions().cend(), 1LL, [](MathLib::bigint i1, const Dimension &dim) {
return i1 * dim.num;
});
Expand All @@ -571,8 +574,6 @@ ValueFlow::Value CheckBufferOverrun::getBufferSize(const Token *bufTok) const

if (var->isPointerArray())
v.intvalue = dim * mSettings->platform.sizeof_pointer;
else if (var->isPointer())
return ValueFlow::Value(-1);
else {
const MathLib::bigint typeSize = bufTok->valueType()->typeSize(mSettings->platform);
v.intvalue = dim * typeSize;
Expand Down

0 comments on commit 60dd27d

Please sign in to comment.