]> granicus.if.org Git - clang/commitdiff
Revert r326782 "[analyzer] CStringChecker.cpp: Remove the duplicated check...".
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 21 Mar 2018 00:57:37 +0000 (00:57 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 21 Mar 2018 00:57:37 +0000 (00:57 +0000)
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

lib/StaticAnalyzer/Checkers/CStringChecker.cpp

index 4eb189e22812a4e4425a900a651c19a88ecddccd..bd4033784ef2f2ed37ae4db87f5636cac5b11fad 100644 (file)
@@ -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;