[PATCH] D42388: [analyzer] Protect against dereferencing a null pointer

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 22 11:38:01 PST 2018


alexshap created this revision.
alexshap added reviewers: NoQ, dcoughlin.
Herald added subscribers: llvm-commits, a.sidorin, szepet, xazax.hun.

The check (inside StackHintGeneratorForSymbol::getMessage)

  if (!N)
      return getMessageForSymbolNotFound()

is moved to the beginning of the function.


Repository:
  rL LLVM

https://reviews.llvm.org/D42388

Files:
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp


Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===================================================================
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -1185,6 +1185,9 @@
 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 @@
   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(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42388.130935.patch
Type: text/x-patch
Size: 767 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180122/36404f34/attachment.bin>


More information about the llvm-commits mailing list