From a54e295df5c36ce6d290105132df332435c76651 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Wed, 21 Mar 2018 00:57:37 +0000 Subject: [PATCH] Revert r326782 "[analyzer] CStringChecker.cpp: Remove the duplicated check...". It seems that the refactoring was causing a functional change and some warnings have disappeared. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328067 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Checkers/CStringChecker.cpp | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index 4eb189e228..bd4033784e 100644 --- a/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -1033,6 +1033,21 @@ void CStringChecker::evalCopyCommon(CheckerContext &C, if (stateNonZeroSize) { state = stateNonZeroSize; + // Ensure the destination is not null. If it is NULL there will be a + // NULL pointer dereference. + state = checkNonNull(C, state, Dest, destVal); + if (!state) + return; + + // Get the value of the Src. + SVal srcVal = state->getSVal(Source, LCtx); + + // Ensure the source is not null. If it is NULL there will be a + // NULL pointer dereference. + state = checkNonNull(C, state, Source, srcVal); + if (!state) + return; + // Ensure the accesses are valid and that the buffers do not overlap. const char * const writeWarning = "Memory copy function overflows destination buffer"; @@ -2018,6 +2033,12 @@ void CStringChecker::evalMemset(CheckerContext &C, const CallExpr *CE) const { return; } + // Ensure the memory area is not null. + // If it is NULL there will be a NULL pointer dereference. + State = checkNonNull(C, StateNonZeroSize, Mem, MemVal); + if (!State) + return; + State = CheckBufferAccess(C, State, Size, Mem); if (!State) return; -- 2.40.0