|
34 | 34 | // Depends on NewDeleteChecker. |
35 | 35 | // |
36 | 36 | // * MismatchedDeallocatorChecker |
37 | | -// Enables checking whether memory is deallocated with the correspending |
| 37 | +// Enables checking whether memory is deallocated with the corresponding |
38 | 38 | // allocation function in MallocChecker, such as malloc() allocated |
39 | 39 | // regions are only freed by free(), new by delete, new[] by delete[]. |
40 | 40 | // |
@@ -1372,8 +1372,8 @@ void MallocChecker::checkIfFreeNameIndex(ProgramStateRef State, |
1372 | 1372 | C.addTransition(State); |
1373 | 1373 | } |
1374 | 1374 |
|
1375 | | -const Expr *getPlacementNewBufferArg(const CallExpr *CE, |
1376 | | - const FunctionDecl *FD) { |
| 1375 | +static const Expr *getPlacementNewBufferArg(const CallExpr *CE, |
| 1376 | + const FunctionDecl *FD) { |
1377 | 1377 | // Checking for signature: |
1378 | 1378 | // void* operator new ( std::size_t count, void* ptr ); |
1379 | 1379 | // void* operator new[]( std::size_t count, void* ptr ); |
@@ -1682,17 +1682,15 @@ ProgramStateRef MallocChecker::ProcessZeroAllocCheck( |
1682 | 1682 | const RefState *RS = State->get<RegionState>(Sym); |
1683 | 1683 | if (RS) { |
1684 | 1684 | if (RS->isAllocated()) |
1685 | | - return TrueState->set<RegionState>(Sym, |
1686 | | - RefState::getAllocatedOfSizeZero(RS)); |
1687 | | - else |
1688 | | - return State; |
1689 | | - } else { |
1690 | | - // Case of zero-size realloc. Historically 'realloc(ptr, 0)' is treated as |
1691 | | - // 'free(ptr)' and the returned value from 'realloc(ptr, 0)' is not |
1692 | | - // tracked. Add zero-reallocated Sym to the state to catch references |
1693 | | - // to zero-allocated memory. |
1694 | | - return TrueState->add<ReallocSizeZeroSymbols>(Sym); |
| 1685 | + return TrueState->set<RegionState>( |
| 1686 | + Sym, RefState::getAllocatedOfSizeZero(RS)); |
| 1687 | + return State; |
1695 | 1688 | } |
| 1689 | + // Case of zero-size realloc. Historically 'realloc(ptr, 0)' is treated as |
| 1690 | + // 'free(ptr)' and the returned value from 'realloc(ptr, 0)' is not |
| 1691 | + // tracked. Add zero-reallocated Sym to the state to catch references |
| 1692 | + // to zero-allocated memory. |
| 1693 | + return TrueState->add<ReallocSizeZeroSymbols>(Sym); |
1696 | 1694 | } |
1697 | 1695 |
|
1698 | 1696 | // Assume the value is non-zero going forward. |
@@ -1890,7 +1888,7 @@ void MallocChecker::reportTaintBug(StringRef Msg, ProgramStateRef State, |
1890 | 1888 | "Tainted Memory Allocation", |
1891 | 1889 | categories::TaintedData)); |
1892 | 1890 | auto R = std::make_unique<PathSensitiveBugReport>(*BT_TaintedAlloc, Msg, N); |
1893 | | - for (auto TaintedSym : TaintedSyms) { |
| 1891 | + for (const auto *TaintedSym : TaintedSyms) { |
1894 | 1892 | R->markInteresting(TaintedSym); |
1895 | 1893 | } |
1896 | 1894 | C.emitReport(std::move(R)); |
@@ -2277,11 +2275,12 @@ MallocChecker::FreeMemAux(CheckerContext &C, const Expr *ArgExpr, |
2277 | 2275 | HandleDoubleFree(C, ParentExpr->getSourceRange(), RsBase->isReleased(), |
2278 | 2276 | SymBase, PreviousRetStatusSymbol); |
2279 | 2277 | return nullptr; |
| 2278 | + } |
2280 | 2279 |
|
2281 | 2280 | // If the pointer is allocated or escaped, but we are now trying to free it, |
2282 | 2281 | // check that the call to free is proper. |
2283 | | - } else if (RsBase->isAllocated() || RsBase->isAllocatedOfSizeZero() || |
2284 | | - RsBase->isEscaped()) { |
| 2282 | + if (RsBase->isAllocated() || RsBase->isAllocatedOfSizeZero() || |
| 2283 | + RsBase->isEscaped()) { |
2285 | 2284 |
|
2286 | 2285 | // Check if an expected deallocation function matches the real one. |
2287 | 2286 | bool DeallocMatchesAlloc = RsBase->getAllocationFamily() == Family; |
@@ -2857,9 +2856,7 @@ MallocChecker::ReallocMemAux(CheckerContext &C, const CallEvent &Call, |
2857 | 2856 |
|
2858 | 2857 | const CallExpr *CE = cast<CallExpr>(Call.getOriginExpr()); |
2859 | 2858 |
|
2860 | | - if (SuffixWithN && CE->getNumArgs() < 3) |
2861 | | - return nullptr; |
2862 | | - else if (CE->getNumArgs() < 2) |
| 2859 | + if ((SuffixWithN && CE->getNumArgs() < 3) || CE->getNumArgs() < 2) |
2863 | 2860 | return nullptr; |
2864 | 2861 |
|
2865 | 2862 | const Expr *arg0Expr = CE->getArg(0); |
|
0 commit comments