diff options
author | Anna Zaks <ganna@apple.com> | 2012-02-13 20:57:07 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2012-02-13 20:57:07 +0000 |
commit | 30838b994527d12e269abb14d395b1878e78c16d (patch) | |
tree | cc6385ec6c816aaf20392044ec99b3b2af1044ff /lib/StaticAnalyzer/Checkers/MallocChecker.cpp | |
parent | 51890355535ec66bc136d6fdd842c2031f541e9d (diff) |
[analyzer] Malloc Checker: realloc: correct the way we are handing the
case when size is 0.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150412 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/MallocChecker.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 98298c850b..9329d5251f 100644 --- a/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -670,18 +670,22 @@ void MallocChecker::ReallocMem(CheckerContext &C, const CallExpr *CE) const { if (PrtIsNull && SizeIsZero) return; + // Get the from and to pointer symbols as in toPtr = realloc(fromPtr, size). assert(!PrtIsNull); + SymbolRef FromPtr = arg0Val.getAsSymbol(); + SVal RetVal = state->getSVal(CE, LCtx); + SymbolRef ToPtr = RetVal.getAsSymbol(); + if (!FromPtr || !ToPtr) + return; // If the size is 0, free the memory. if (SizeIsZero) if (ProgramStateRef stateFree = FreeMemAux(C, CE, StateSizeIsZero,0,false)){ - // Bind the return value to NULL because it is now free. - // TODO: This is tricky. Does not currently work. // The semantics of the return value are: // If size was equal to 0, either NULL or a pointer suitable to be passed // to free() is returned. - C.addTransition(stateFree->BindExpr(CE, LCtx, - svalBuilder.makeNull(), true)); + stateFree = stateFree->set<ReallocPairs>(ToPtr, FromPtr); + C.addTransition(stateFree); return; } @@ -690,10 +694,7 @@ void MallocChecker::ReallocMem(CheckerContext &C, const CallExpr *CE) const { // FIXME: We should copy the content of the original buffer. ProgramStateRef stateRealloc = MallocMemAux(C, CE, CE->getArg(1), UnknownVal(), stateFree); - SymbolRef FromPtr = arg0Val.getAsSymbol(); - SVal RetVal = state->getSVal(CE, LCtx); - SymbolRef ToPtr = RetVal.getAsSymbol(); - if (!stateRealloc || !FromPtr || !ToPtr) + if (!stateRealloc) return; stateRealloc = stateRealloc->set<ReallocPairs>(ToPtr, FromPtr); C.addTransition(stateRealloc); |