r328067 - Revert r326782 "[analyzer] CStringChecker.cpp: Remove the duplicated check...".

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 20 17:57:37 PDT 2018


Author: dergachev
Date: Tue Mar 20 17:57:37 2018
New Revision: 328067

URL: http://llvm.org/viewvc/llvm-project?rev=328067&view=rev
Log:
Revert r326782 "[analyzer] CStringChecker.cpp: Remove the duplicated check...".

It seems that the refactoring was causing a functional change and some warnings
have disappeared.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=328067&r1=328066&r2=328067&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Tue Mar 20 17:57:37 2018
@@ -1033,6 +1033,21 @@ void CStringChecker::evalCopyCommon(Chec
   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(CheckerC
     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;




More information about the cfe-commits mailing list