]> granicus.if.org Git - clang/commitdiff
[analyzer] Protect against dereferencing a null pointer
authorAlexander Shaposhnikov <shal1t712@gmail.com>
Mon, 22 Jan 2018 20:18:42 +0000 (20:18 +0000)
committerAlexander Shaposhnikov <shal1t712@gmail.com>
Mon, 22 Jan 2018 20:18:42 +0000 (20:18 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323146 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/PathDiagnostic.cpp

index b03517c02a80387f41e18f8598bed346f316821a..fd3de613840da2937493a0d9d8c5282e8dbf1234 100644 (file)
@@ -1185,6 +1185,9 @@ void PathDiagnostic::FullProfile(llvm::FoldingSetNodeID &ID) const {
 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::getMessage(const ExplodedNode *N){
   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(),