r323146 - [analyzer] Protect against dereferencing a null pointer

Alexander Shaposhnikov via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 22 12:18:42 PST 2018


Author: alexshap
Date: Mon Jan 22 12:18:42 2018
New Revision: 323146

URL: http://llvm.org/viewvc/llvm-project?rev=323146&view=rev
Log:
[analyzer] Protect against dereferencing a null pointer

The check (inside StackHintGeneratorForSymbol::getMessage)
if (!N)
    return getMessageForSymbolNotFound()
is moved to the beginning of the function.

Differential revision: https://reviews.llvm.org/D42388

Test plan: make check-all

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=323146&r1=323145&r2=323146&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Mon Jan 22 12:18:42 2018
@@ -1185,6 +1185,9 @@ void PathDiagnostic::FullProfile(llvm::F
 StackHintGenerator::~StackHintGenerator() {}
 
 std::string StackHintGeneratorForSymbol::getMessage(const ExplodedNode *N){
+  if (!N)
+    return getMessageForSymbolNotFound();
+
   ProgramPoint P = N->getLocation();
   CallExitEnd CExit = P.castAs<CallExitEnd>();
 
@@ -1194,9 +1197,6 @@ std::string StackHintGeneratorForSymbol:
   if (!CE)
     return "";
 
-  if (!N)
-    return getMessageForSymbolNotFound();
-
   // Check if one of the parameters are set to the interesting symbol.
   unsigned ArgIndex = 0;
   for (CallExpr::const_arg_iterator I = CE->arg_begin(),




More information about the cfe-commits mailing list