diff options
author | Anna Zaks <ganna@apple.com> | 2012-02-22 02:36:01 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-02-22 02:36:01 +0000 |
commit | 4ca45b1d00e97c590bc1bf012bd35b1f73926565 (patch) | |
tree | df00410caf12153eaee92bb7e598367bb6eacfea /clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | |
parent | 3705a1ee1014e22b4d54a4f00bfa7610b03dd45b (diff) | |
download | bcm5719-llvm-4ca45b1d00e97c590bc1bf012bd35b1f73926565.tar.gz bcm5719-llvm-4ca45b1d00e97c590bc1bf012bd35b1f73926565.zip |
[analyzer] Malloc: fix another false positive.
, when we return a symbol reachable to the malloced one via pointer
arithmetic.
llvm-svn: 151121
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index fed64f1b042..e21dde1f826 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -881,7 +881,17 @@ void MallocChecker::checkPreStmt(const ReturnStmt *S, CheckerContext &C) const { return; // Check if we are returning a symbol. - SymbolRef Sym = C.getState()->getSVal(E, C.getLocationContext()).getAsSymbol(); + SVal RetVal = C.getState()->getSVal(E, C.getLocationContext()); + SymbolRef Sym = RetVal.getAsSymbol(); + if (!Sym) + // If we are returning a field of the allocated struct or an array element, + // the callee could still free the memory. + // TODO: This logic should be a part of generic symbol escape callback. + if (const MemRegion *MR = RetVal.getAsRegion()) + if (isa<FieldRegion>(MR) || isa<ElementRegion>(MR)) + if (const SymbolicRegion *BMR = + dyn_cast<SymbolicRegion>(MR->getBaseRegion())) + Sym = BMR->getSymbol(); if (!Sym) return; |