Bug Summary

File:tools/lldb/tools/lldb-mi/MICmdFactory.cpp
Warning:line 152, column 5
Value stored to 'bValid' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name MICmdFactory.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D HAVE_ROUND -D LLDB_CONFIGURATION_RELEASE -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/lldb/tools/lldb-mi -I /build/llvm-toolchain-snapshot-8~svn345461/tools/lldb/tools/lldb-mi -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/lldb/include -I /build/llvm-toolchain-snapshot-8~svn345461/tools/lldb/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn345461/include -I /usr/include/python2.7 -I /build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/lldb/../clang/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/lldb/tools/lldb-mi -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-10-27-211344-32123-1 -x c++ /build/llvm-toolchain-snapshot-8~svn345461/tools/lldb/tools/lldb-mi/MICmdFactory.cpp -faddrsig
1//===-- MICmdFactory.cpp ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// In-house headers:
11#include "MICmdFactory.h"
12#include "MICmdBase.h"
13#include "MICmdCommands.h"
14#include "MICmdData.h"
15#include "MICmnResources.h"
16
17//++
18//------------------------------------------------------------------------------------
19// Details: CMICmdFactory constructor.
20// Type: Method.
21// Args: None.
22// Return: None.
23// Throws: None.
24//--
25CMICmdFactory::CMICmdFactory() {}
26
27//++
28//------------------------------------------------------------------------------------
29// Details: CMICmdFactory destructor.
30// Type: Overridable.
31// Args: None.
32// Return: None.
33// Throws: None.
34//--
35CMICmdFactory::~CMICmdFactory() { Shutdown(); }
36
37//++
38//------------------------------------------------------------------------------------
39// Details: Initialize resources for *this Command factory.
40// Type: Method.
41// Args: None.
42// Return: MIstatus::success - Functionality succeeded.
43// MIstatus::failure - Functionality failed.
44// Throws: None.
45//--
46bool CMICmdFactory::Initialize() {
47 m_clientUsageRefCnt++;
48
49 if (m_bInitialized)
50 return MIstatus::success;
51
52 m_bInitialized = true;
53
54 MICmnCommands::RegisterAll();
55
56 return MIstatus::success;
57}
58
59//++
60//------------------------------------------------------------------------------------
61// Details: Release resources for *this Command Factory.
62// Type: Method.
63// Args: None.
64// Return: MIstatus::success - Functionality succeeded.
65// MIstatus::failure - Functionality failed.
66// Throws: None.
67//--
68bool CMICmdFactory::Shutdown() {
69 if (--m_clientUsageRefCnt > 0)
70 return MIstatus::success;
71
72 if (!m_bInitialized)
73 return MIstatus::success;
74
75 m_mapMiCmdToCmdCreatorFn.clear();
76
77 m_bInitialized = false;
78
79 return MIstatus::success;
80}
81
82//++
83//------------------------------------------------------------------------------------
84// Details: Register a command's creator function with the command identifier
85// the MI
86// command name i.e. 'file-exec-and-symbols'.
87// Type: Method.
88// Args: vMiCmd - (R) Command's name, the MI command.
89// vCmdCreateFn - (R) Command's creator function pointer.
90// Return: MIstatus::success - Functionality succeeded.
91// MIstatus::failure - Functionality failed.
92// Throws: None.
93//--
94bool CMICmdFactory::CmdRegister(const CMIUtilString &vMiCmd,
95 CmdCreatorFnPtr vCmdCreateFn) {
96 if (!IsValid(vMiCmd)) {
97 SetErrorDescription(CMIUtilString::Format(
98 MIRSRC(IDS_CMDFACTORY_ERR_INVALID_CMD_NAME)CMICmnResources::Instance().GetString(IDS_CMDFACTORY_ERR_INVALID_CMD_NAME
).c_str()
, vMiCmd.c_str()));
99 return MIstatus::failure;
100 }
101 if (vCmdCreateFn == nullptr) {
102 SetErrorDescription(CMIUtilString::Format(
103 MIRSRC(IDS_CMDFACTORY_ERR_INVALID_CMD_CR8FN)CMICmnResources::Instance().GetString(IDS_CMDFACTORY_ERR_INVALID_CMD_CR8FN
).c_str()
, vMiCmd.c_str()));
104 return MIstatus::failure;
105 }
106
107 if (HaveAlready(vMiCmd)) {
108 SetErrorDescription(CMIUtilString::Format(
109 MIRSRC(IDS_CMDFACTORY_ERR_CMD_ALREADY_REGED)CMICmnResources::Instance().GetString(IDS_CMDFACTORY_ERR_CMD_ALREADY_REGED
).c_str()
, vMiCmd.c_str()));
110 return MIstatus::failure;
111 }
112
113 MapPairMiCmdToCmdCreatorFn_t pr(vMiCmd, vCmdCreateFn);
114 m_mapMiCmdToCmdCreatorFn.insert(pr);
115
116 return MIstatus::success;
117}
118
119//++
120//------------------------------------------------------------------------------------
121// Details: Check a command is already registered.
122// Type: Method.
123// Args: vMiCmd - (R) Command's name, the MI command.
124// Return: True - registered.
125// False - not found.
126// Throws: None.
127//--
128bool CMICmdFactory::HaveAlready(const CMIUtilString &vMiCmd) const {
129 const MapMiCmdToCmdCreatorFn_t::const_iterator it =
130 m_mapMiCmdToCmdCreatorFn.find(vMiCmd);
131 if (it != m_mapMiCmdToCmdCreatorFn.end())
132 return true;
133
134 return false;
135}
136
137//++
138//------------------------------------------------------------------------------------
139// Details: Check a command's name is valid:
140// - name is not empty
141// - name does not have spaces
142// Type: Method.
143// Args: vMiCmd - (R) Command's name, the MI command.
144// Return: True - valid.
145// False - not valid.
146// Throws: None.
147//--
148bool CMICmdFactory::IsValid(const CMIUtilString &vMiCmd) const {
149 bool bValid = true;
150
151 if (vMiCmd.empty()) {
152 bValid = false;
Value stored to 'bValid' is never read
153 return false;
154 }
155
156 const size_t nPos = vMiCmd.find(' ');
157 if (nPos != std::string::npos)
158 bValid = false;
159
160 return bValid;
161}
162
163//++
164//------------------------------------------------------------------------------------
165// Details: Check a command is already registered.
166// Type: Method.
167// Args: vMiCmd - (R) Command's name, the MI command.
168// Return: True - registered.
169// False - not found.
170// Throws: None.
171//--
172bool CMICmdFactory::CmdExist(const CMIUtilString &vMiCmd) const {
173 return HaveAlready(vMiCmd);
174}
175
176//++
177//------------------------------------------------------------------------------------
178// Details: Create a command given the specified MI command name. The command
179// data object
180// contains the options for the command.
181// Type: Method.
182// Args: vMiCmd - (R) Command's name, the MI command.
183// vCmdData - (RW) Command's metadata status/information/result
184// object.
185// vpNewCmd - (W) New command instance.
186// Return: MIstatus::success - Functionality succeeded.
187// MIstatus::failure - Functionality failed.
188// Throws: None.
189//--
190bool CMICmdFactory::CmdCreate(const CMIUtilString &vMiCmd,
191 const SMICmdData &vCmdData,
192 CMICmdBase *&vpNewCmd) {
193 vpNewCmd = nullptr;
194
195 if (!IsValid(vMiCmd)) {
196 SetErrorDescription(CMIUtilString::Format(
197 MIRSRC(IDS_CMDFACTORY_ERR_INVALID_CMD_NAME)CMICmnResources::Instance().GetString(IDS_CMDFACTORY_ERR_INVALID_CMD_NAME
).c_str()
, vMiCmd.c_str()));
198 return MIstatus::failure;
199 }
200 if (!HaveAlready(vMiCmd)) {
201 SetErrorDescription(CMIUtilString::Format(
202 MIRSRC(IDS_CMDFACTORY_ERR_CMD_NOT_REGISTERED)CMICmnResources::Instance().GetString(IDS_CMDFACTORY_ERR_CMD_NOT_REGISTERED
).c_str()
, vMiCmd.c_str()));
203 return MIstatus::failure;
204 }
205
206 const MapMiCmdToCmdCreatorFn_t::const_iterator it =
207 m_mapMiCmdToCmdCreatorFn.find(vMiCmd);
208 const CMIUtilString &rMiCmd((*it).first);
209 MIunused(rMiCmd)(void)rMiCmd;;
210 CmdCreatorFnPtr pFn = (*it).second;
211 CMICmdBase *pCmd = (*pFn)();
212
213 SMICmdData cmdData(vCmdData);
214 cmdData.id = pCmd->GetGUID();
215 pCmd->SetCmdData(cmdData);
216 vpNewCmd = pCmd;
217
218 return MIstatus::success;
219}