Skip to content

Commit 2430156

Browse files
committed
[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. Part 3
Improve LLDB reliability by fixing the following "uninitialized variables" static code inspection warnings from scan.coverity.com/projects/llvm: 1355854, 1347549, 1316348, 1372028, 1431625, 1315634, 1315637, 1355855, 1364803, 1420505, 1420563, 1420685, 1366014, 1203966, 1204029, 1204031, 1204032, 1328411, 1325969, 1325968, 1374921, 1094809 Differential Revision: https://reviews.llvm.org/D130602
1 parent 0562cf4 commit 2430156

File tree

15 files changed

+38
-33
lines changed

15 files changed

+38
-33
lines changed

lldb/include/lldb/Core/LoadedModuleInfoList.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ class LoadedModuleInfoList {
9595
protected:
9696
bool m_has[e_num];
9797
std::string m_name;
98-
lldb::addr_t m_link_map;
99-
lldb::addr_t m_base;
100-
bool m_base_is_offset;
101-
lldb::addr_t m_dynamic;
98+
lldb::addr_t m_link_map = LLDB_INVALID_ADDRESS;
99+
lldb::addr_t m_base = LLDB_INVALID_ADDRESS;
100+
bool m_base_is_offset = false;
101+
lldb::addr_t m_dynamic = LLDB_INVALID_ADDRESS;
102102
};
103103

104104
LoadedModuleInfoList() = default;

lldb/include/lldb/DataFormatters/TypeSummary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class TypeSummaryImpl {
263263
typedef std::shared_ptr<TypeSummaryImpl> SharedPointer;
264264

265265
protected:
266-
uint32_t m_my_revision;
266+
uint32_t m_my_revision = 0;
267267
Flags m_flags;
268268

269269
TypeSummaryImpl(Kind kind, const TypeSummaryImpl::Flags &flags);

lldb/include/lldb/Symbol/DebugMacros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DebugMacroEntry {
3939
static DebugMacroEntry
4040
CreateIndirectEntry(const DebugMacrosSP &debug_macros_sp);
4141

42-
DebugMacroEntry() : m_type(INVALID) {}
42+
DebugMacroEntry() : m_type(INVALID), m_line(0), m_debug_line_file_idx(0) {}
4343

4444
~DebugMacroEntry() = default;
4545

lldb/include/lldb/Target/ProcessStructReader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class ProcessStructReader {
3939

4040
public:
4141
ProcessStructReader(Process *process, lldb::addr_t base_addr,
42-
CompilerType struct_type) {
42+
CompilerType struct_type)
43+
: m_byte_order(lldb::eByteOrderInvalid), m_addr_byte_size(0) {
4344
if (!process)
4445
return;
4546
if (base_addr == 0 || base_addr == LLDB_INVALID_ADDRESS)

lldb/include/lldb/Utility/Args.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Args {
3939
friend struct llvm::yaml::MappingTraits<Args::ArgEntry>;
4040

4141
std::unique_ptr<char[]> ptr;
42-
char quote;
42+
char quote = '\0';
4343

4444
char *data() { return ptr.get(); }
4545

@@ -395,7 +395,7 @@ template <> struct MappingTraits<lldb_private::Args::ArgEntry> {
395395
return lldb_private::Args::ArgEntry(value, quote);
396396
}
397397
StringRef value;
398-
uint8_t quote;
398+
uint8_t quote = '\0';
399399
};
400400
static void mapping(IO &io, lldb_private::Args::ArgEntry &v);
401401
};

lldb/include/lldb/Utility/RegisterValue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ class RegisterValue {
263263
mutable uint8_t
264264
bytes[kMaxRegisterByteSize]; // This must be big enough to hold any
265265
// register for any supported target.
266-
uint16_t length;
267-
lldb::ByteOrder byte_order;
266+
uint16_t length = 0;
267+
lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
268268
} buffer;
269269
};
270270

lldb/include/lldb/Utility/StringExtractorGDBRemote.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class StringExtractorGDBRemote : public StringExtractor {
215215

216216
protected:
217217
ResponseValidatorCallback m_validator = nullptr;
218-
void *m_validator_baton;
218+
void *m_validator_baton = nullptr;
219219
};
220220

221221
#endif // LLDB_UTILITY_STRINGEXTRACTORGDBREMOTE_H

lldb/source/Breakpoint/BreakpointOptions.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ BreakpointOptions::BreakpointOptions(bool all_flags_set)
115115
: m_callback(BreakpointOptions::NullCallback),
116116
m_baton_is_command_baton(false), m_callback_is_synchronous(false),
117117
m_enabled(true), m_one_shot(false), m_ignore_count(0),
118-
m_condition_text_hash(0), m_auto_continue(false), m_set_flags(0) {
118+
m_condition_text_hash(0), m_inject_condition(false),
119+
m_auto_continue(false), m_set_flags(0) {
119120
if (all_flags_set)
120121
m_set_flags.Set(~((Flags::ValueType)0));
121122
}
@@ -125,11 +126,9 @@ BreakpointOptions::BreakpointOptions(const char *condition, bool enabled,
125126
bool auto_continue)
126127
: m_callback(nullptr), m_baton_is_command_baton(false),
127128
m_callback_is_synchronous(false), m_enabled(enabled),
128-
m_one_shot(one_shot), m_ignore_count(ignore),
129-
m_condition_text_hash(0), m_auto_continue(auto_continue)
130-
{
131-
m_set_flags.Set(eEnabled | eIgnoreCount | eOneShot
132-
| eAutoContinue);
129+
m_one_shot(one_shot), m_ignore_count(ignore), m_condition_text_hash(0),
130+
m_inject_condition(false), m_auto_continue(auto_continue) {
131+
m_set_flags.Set(eEnabled | eIgnoreCount | eOneShot | eAutoContinue);
133132
if (condition && *condition != '\0') {
134133
SetCondition(condition);
135134
}
@@ -141,8 +140,8 @@ BreakpointOptions::BreakpointOptions(const BreakpointOptions &rhs)
141140
m_baton_is_command_baton(rhs.m_baton_is_command_baton),
142141
m_callback_is_synchronous(rhs.m_callback_is_synchronous),
143142
m_enabled(rhs.m_enabled), m_one_shot(rhs.m_one_shot),
144-
m_ignore_count(rhs.m_ignore_count), m_auto_continue(rhs.m_auto_continue),
145-
m_set_flags(rhs.m_set_flags) {
143+
m_ignore_count(rhs.m_ignore_count), m_inject_condition(false),
144+
m_auto_continue(rhs.m_auto_continue), m_set_flags(rhs.m_set_flags) {
146145
if (rhs.m_thread_spec_up != nullptr)
147146
m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
148147
m_condition_text = rhs.m_condition_text;
@@ -163,6 +162,7 @@ operator=(const BreakpointOptions &rhs) {
163162
m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
164163
m_condition_text = rhs.m_condition_text;
165164
m_condition_text_hash = rhs.m_condition_text_hash;
165+
m_inject_condition = rhs.m_inject_condition;
166166
m_auto_continue = rhs.m_auto_continue;
167167
m_set_flags = rhs.m_set_flags;
168168
return *this;

lldb/source/Core/Debugger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
201201
}
202202

203203
TargetSP target_sp;
204-
LoadScriptFromSymFile load_script_old_value;
204+
LoadScriptFromSymFile load_script_old_value = eLoadScriptFromSymFileFalse;
205205
if (is_load_script && exe_ctx->GetTargetSP()) {
206206
target_sp = exe_ctx->GetTargetSP();
207207
load_script_old_value =

lldb/source/Core/IOHandlerCursesGUI.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,10 @@ class Window : public Surface {
588588
}
589589

590590
Window(const char *name, const Rect &bounds)
591-
: Surface(Surface::Type::Window), m_name(name), m_parent(nullptr),
592-
m_subwindows(), m_delegate_sp(), m_curr_active_window_idx(UINT32_MAX),
593-
m_prev_active_window_idx(UINT32_MAX), m_delete(true),
591+
: Surface(Surface::Type::Window), m_name(name), m_panel(nullptr),
592+
m_parent(nullptr), m_subwindows(), m_delegate_sp(),
593+
m_curr_active_window_idx(UINT32_MAX),
594+
m_prev_active_window_idx(UINT32_MAX), m_delete(false),
594595
m_needs_update(true), m_can_activate(true), m_is_subwin(false) {
595596
Reset(::newwin(bounds.size.height, bounds.size.width, bounds.origin.y,
596597
bounds.origin.y));
@@ -5702,8 +5703,8 @@ class ValueObjectListDelegate : public WindowDelegate {
57025703
uint32_t m_selected_row_idx = 0;
57035704
uint32_t m_first_visible_row = 0;
57045705
uint32_t m_num_rows = 0;
5705-
int m_min_x;
5706-
int m_min_y;
5706+
int m_min_x = 0;
5707+
int m_min_y = 0;
57075708
int m_max_x = 0;
57085709
int m_max_y = 0;
57095710

lldb/source/Expression/FunctionCaller.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ FunctionCaller::FunctionCaller(ExecutionContextScope &exe_scope,
4444
m_function_return_type(return_type),
4545
m_wrapper_function_name("__lldb_caller_function"),
4646
m_wrapper_struct_name("__lldb_caller_struct"), m_wrapper_args_addrs(),
47-
m_struct_valid(false), m_arg_values(arg_value_list), m_compiled(false),
47+
m_struct_valid(false), m_struct_size(0), m_return_size(0),
48+
m_return_offset(0), m_arg_values(arg_value_list), m_compiled(false),
4849
m_JITted(false) {
4950
m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
5051
// Can't make a FunctionCaller without a process.

lldb/source/Expression/LLVMUserExpression.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ LLVMUserExpression::LLVMUserExpression(ExecutionContextScope &exe_scope,
4848
m_stack_frame_bottom(LLDB_INVALID_ADDRESS),
4949
m_stack_frame_top(LLDB_INVALID_ADDRESS), m_allow_cxx(false),
5050
m_allow_objc(false), m_transformed_text(), m_execution_unit_sp(),
51-
m_materializer_up(), m_jit_module_wp(), m_can_interpret(false),
52-
m_materialized_address(LLDB_INVALID_ADDRESS) {}
51+
m_materializer_up(), m_jit_module_wp(), m_target(nullptr),
52+
m_can_interpret(false), m_materialized_address(LLDB_INVALID_ADDRESS) {}
5353

5454
LLVMUserExpression::~LLVMUserExpression() {
5555
if (m_target) {

lldb/source/Host/common/MainLoop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void MainLoop::RunImpl::ProcessEvents() {
255255
}
256256
#endif
257257

258-
MainLoop::MainLoop() {
258+
MainLoop::MainLoop() : m_terminate_request(false) {
259259
#if HAVE_SYS_EVENT_H
260260
m_kqueue = kqueue();
261261
assert(m_kqueue >= 0);

lldb/source/Interpreter/OptionGroupFormat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ OptionGroupFormat::OptionGroupFormat(
3737
: m_format(default_format, default_format),
3838
m_byte_size(default_byte_size, default_byte_size),
3939
m_count(default_count, default_count), m_prev_gdb_format('x'),
40-
m_prev_gdb_size('w') {
40+
m_prev_gdb_size('w'), m_has_gdb_format(false) {
4141
// Copy the default option definitions.
4242
std::copy(std::begin(g_default_option_definitions),
4343
std::end(g_default_option_definitions),

lldb/source/Interpreter/OptionGroupVariable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ static Status ValidateSummaryString(const char *str, void *) {
6767
}
6868

6969
OptionGroupVariable::OptionGroupVariable(bool show_frame_options)
70-
: include_frame_options(show_frame_options), summary(ValidateNamedSummary),
71-
summary_string(ValidateSummaryString) {}
70+
: include_frame_options(show_frame_options), show_args(false),
71+
show_recognized_args(false), show_locals(false), show_globals(false),
72+
use_regex(false), show_scope(false), show_decl(false),
73+
summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}
7274

7375
Status
7476
OptionGroupVariable::SetOptionValue(uint32_t option_idx,

0 commit comments

Comments
 (0)