diff options
author | Baranov Victor <bar.victor.2002@gmail.com> | 2025-06-27 10:33:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-27 10:33:09 +0300 |
commit | 8a839ea79123175c940a64beea6abd29b8b302fb (patch) | |
tree | a2ffb7b9dcb39073ac0ced0154c17ef81cf62962 /clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | |
parent | 205dcf7146ceeb586953300c123656b0ef3768e3 (diff) | |
download | llvm-8a839ea79123175c940a64beea6abd29b8b302fb.zip llvm-8a839ea79123175c940a64beea6abd29b8b302fb.tar.gz llvm-8a839ea79123175c940a64beea6abd29b8b302fb.tar.bz2 |
[analyzer][NFC] Fix clang-tidy warning in Malloc and UnixApi checkers (#145719)
Mostly `else-after-return` and `else-after-continue` warnings
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index fa6e8e4..a33e61f 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -34,7 +34,7 @@ // Depends on NewDeleteChecker. // // * MismatchedDeallocatorChecker -// Enables checking whether memory is deallocated with the correspending +// Enables checking whether memory is deallocated with the corresponding // allocation function in MallocChecker, such as malloc() allocated // regions are only freed by free(), new by delete, new[] by delete[]. // @@ -1372,8 +1372,8 @@ void MallocChecker::checkIfFreeNameIndex(ProgramStateRef State, C.addTransition(State); } -const Expr *getPlacementNewBufferArg(const CallExpr *CE, - const FunctionDecl *FD) { +static const Expr *getPlacementNewBufferArg(const CallExpr *CE, + const FunctionDecl *FD) { // Checking for signature: // void* operator new ( std::size_t count, void* ptr ); // void* operator new[]( std::size_t count, void* ptr ); @@ -1682,17 +1682,15 @@ ProgramStateRef MallocChecker::ProcessZeroAllocCheck( const RefState *RS = State->get<RegionState>(Sym); if (RS) { if (RS->isAllocated()) - return TrueState->set<RegionState>(Sym, - RefState::getAllocatedOfSizeZero(RS)); - else - return State; - } else { - // Case of zero-size realloc. Historically 'realloc(ptr, 0)' is treated as - // 'free(ptr)' and the returned value from 'realloc(ptr, 0)' is not - // tracked. Add zero-reallocated Sym to the state to catch references - // to zero-allocated memory. - return TrueState->add<ReallocSizeZeroSymbols>(Sym); + return TrueState->set<RegionState>( + Sym, RefState::getAllocatedOfSizeZero(RS)); + return State; } + // Case of zero-size realloc. Historically 'realloc(ptr, 0)' is treated as + // 'free(ptr)' and the returned value from 'realloc(ptr, 0)' is not + // tracked. Add zero-reallocated Sym to the state to catch references + // to zero-allocated memory. + return TrueState->add<ReallocSizeZeroSymbols>(Sym); } // Assume the value is non-zero going forward. @@ -1890,7 +1888,7 @@ void MallocChecker::reportTaintBug(StringRef Msg, ProgramStateRef State, "Tainted Memory Allocation", categories::TaintedData)); auto R = std::make_unique<PathSensitiveBugReport>(*BT_TaintedAlloc, Msg, N); - for (auto TaintedSym : TaintedSyms) { + for (const auto *TaintedSym : TaintedSyms) { R->markInteresting(TaintedSym); } C.emitReport(std::move(R)); @@ -2277,11 +2275,12 @@ MallocChecker::FreeMemAux(CheckerContext &C, const Expr *ArgExpr, HandleDoubleFree(C, ParentExpr->getSourceRange(), RsBase->isReleased(), SymBase, PreviousRetStatusSymbol); return nullptr; + } // If the pointer is allocated or escaped, but we are now trying to free it, // check that the call to free is proper. - } else if (RsBase->isAllocated() || RsBase->isAllocatedOfSizeZero() || - RsBase->isEscaped()) { + if (RsBase->isAllocated() || RsBase->isAllocatedOfSizeZero() || + RsBase->isEscaped()) { // Check if an expected deallocation function matches the real one. bool DeallocMatchesAlloc = RsBase->getAllocationFamily() == Family; @@ -2857,9 +2856,7 @@ MallocChecker::ReallocMemAux(CheckerContext &C, const CallEvent &Call, const CallExpr *CE = cast<CallExpr>(Call.getOriginExpr()); - if (SuffixWithN && CE->getNumArgs() < 3) - return nullptr; - else if (CE->getNumArgs() < 2) + if ((SuffixWithN && CE->getNumArgs() < 3) || CE->getNumArgs() < 2) return nullptr; const Expr *arg0Expr = CE->getArg(0); |