From: Alexander Shaposhnikov Date: Mon, 22 Jan 2018 20:18:42 +0000 (+0000) Subject: [analyzer] Protect against dereferencing a null pointer X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=429a73d17b0cb222560c447fab5570184dee582e;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323146 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index b03517c02a..fd3de61384 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -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(); @@ -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(),