Skip to content

Commit 2ffd0df

Browse files
author
mxms
committed
Try harder to find an element we can analyze
Add logic to handle MemberExprs, so we can attempt to find the size information for the struct member variables. This is probably still incomplete in terms of the full space of expressions, but eh, just needs to be better, not perfect.
1 parent 3cdadc6 commit 2ffd0df

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,16 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
439439
dyn_cast<StringLiteral>(Node.getBase()->IgnoreParenImpCasts());
440440
uint64_t size;
441441

442-
if (!BaseDRE && !SLiteral)
443-
return false;
442+
if (!BaseDRE && !SLiteral) {
443+
// Try harder to find something that looks like a DeclRefExpr
444+
const auto *Member = dyn_cast<MemberExpr>(Node.getBase()->IgnoreParenImpCasts());
445+
if (!Member) return false;
446+
447+
const auto *Value = Finder->getASTContext().getAsConstantArrayType(Member->getMemberDecl()->getType());
448+
if (!Value) return false;
449+
450+
size = Value->getLimitedSize();
451+
}
444452

445453
if (BaseDRE) {
446454
if (!BaseDRE->getDecl())

0 commit comments

Comments
 (0)