[Lldb-commits] [lldb] 2430156 - [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan. Part 3

Slava Gurevich via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 27 10:40:28 PDT 2022


Author: Slava Gurevich
Date: 2022-07-27T10:39:49-07:00
New Revision: 24301569f080d60f644d7a69496596cbd65079ce

URL: https://github.com/llvm/llvm-project/commit/24301569f080d60f644d7a69496596cbd65079ce
DIFF: https://github.com/llvm/llvm-project/commit/24301569f080d60f644d7a69496596cbd65079ce.diff

LOG: [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

Added: 
    

Modified: 
    lldb/include/lldb/Core/LoadedModuleInfoList.h
    lldb/include/lldb/DataFormatters/TypeSummary.h
    lldb/include/lldb/Symbol/DebugMacros.h
    lldb/include/lldb/Target/ProcessStructReader.h
    lldb/include/lldb/Utility/Args.h
    lldb/include/lldb/Utility/RegisterValue.h
    lldb/include/lldb/Utility/StringExtractorGDBRemote.h
    lldb/source/Breakpoint/BreakpointOptions.cpp
    lldb/source/Core/Debugger.cpp
    lldb/source/Core/IOHandlerCursesGUI.cpp
    lldb/source/Expression/FunctionCaller.cpp
    lldb/source/Expression/LLVMUserExpression.cpp
    lldb/source/Host/common/MainLoop.cpp
    lldb/source/Interpreter/OptionGroupFormat.cpp
    lldb/source/Interpreter/OptionGroupVariable.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Core/LoadedModuleInfoList.h b/lldb/include/lldb/Core/LoadedModuleInfoList.h
index 6ff4565458407..537a2b0f1d379 100644
--- a/lldb/include/lldb/Core/LoadedModuleInfoList.h
+++ b/lldb/include/lldb/Core/LoadedModuleInfoList.h
@@ -95,10 +95,10 @@ class LoadedModuleInfoList {
   protected:
     bool m_has[e_num];
     std::string m_name;
-    lldb::addr_t m_link_map;
-    lldb::addr_t m_base;
-    bool m_base_is_offset;
-    lldb::addr_t m_dynamic;
+    lldb::addr_t m_link_map = LLDB_INVALID_ADDRESS;
+    lldb::addr_t m_base = LLDB_INVALID_ADDRESS;
+    bool m_base_is_offset = false;
+    lldb::addr_t m_dynamic = LLDB_INVALID_ADDRESS;
   };
 
   LoadedModuleInfoList() = default;

diff  --git a/lldb/include/lldb/DataFormatters/TypeSummary.h b/lldb/include/lldb/DataFormatters/TypeSummary.h
index 30bc8cbf3feb3..a82641021dad3 100644
--- a/lldb/include/lldb/DataFormatters/TypeSummary.h
+++ b/lldb/include/lldb/DataFormatters/TypeSummary.h
@@ -263,7 +263,7 @@ class TypeSummaryImpl {
   typedef std::shared_ptr<TypeSummaryImpl> SharedPointer;
 
 protected:
-  uint32_t m_my_revision;
+  uint32_t m_my_revision = 0;
   Flags m_flags;
 
   TypeSummaryImpl(Kind kind, const TypeSummaryImpl::Flags &flags);

diff  --git a/lldb/include/lldb/Symbol/DebugMacros.h b/lldb/include/lldb/Symbol/DebugMacros.h
index 0ea70f5deb84a..fbc5be0ee6013 100644
--- a/lldb/include/lldb/Symbol/DebugMacros.h
+++ b/lldb/include/lldb/Symbol/DebugMacros.h
@@ -39,7 +39,7 @@ class DebugMacroEntry {
   static DebugMacroEntry
   CreateIndirectEntry(const DebugMacrosSP &debug_macros_sp);
 
-  DebugMacroEntry() : m_type(INVALID) {}
+  DebugMacroEntry() : m_type(INVALID), m_line(0), m_debug_line_file_idx(0) {}
 
   ~DebugMacroEntry() = default;
 

diff  --git a/lldb/include/lldb/Target/ProcessStructReader.h b/lldb/include/lldb/Target/ProcessStructReader.h
index 8046ef4958bbe..4af51cac32890 100644
--- a/lldb/include/lldb/Target/ProcessStructReader.h
+++ b/lldb/include/lldb/Target/ProcessStructReader.h
@@ -39,7 +39,8 @@ class ProcessStructReader {
 
 public:
   ProcessStructReader(Process *process, lldb::addr_t base_addr,
-                      CompilerType struct_type) {
+                      CompilerType struct_type)
+      : m_byte_order(lldb::eByteOrderInvalid), m_addr_byte_size(0) {
     if (!process)
       return;
     if (base_addr == 0 || base_addr == LLDB_INVALID_ADDRESS)

diff  --git a/lldb/include/lldb/Utility/Args.h b/lldb/include/lldb/Utility/Args.h
index cecf6b1502b5b..7c20288aac72d 100644
--- a/lldb/include/lldb/Utility/Args.h
+++ b/lldb/include/lldb/Utility/Args.h
@@ -39,7 +39,7 @@ class Args {
     friend struct llvm::yaml::MappingTraits<Args::ArgEntry>;
 
     std::unique_ptr<char[]> ptr;
-    char quote;
+    char quote = '\0';
 
     char *data() { return ptr.get(); }
 
@@ -395,7 +395,7 @@ template <> struct MappingTraits<lldb_private::Args::ArgEntry> {
       return lldb_private::Args::ArgEntry(value, quote);
     }
     StringRef value;
-    uint8_t quote;
+    uint8_t quote = '\0';
   };
   static void mapping(IO &io, lldb_private::Args::ArgEntry &v);
 };

diff  --git a/lldb/include/lldb/Utility/RegisterValue.h b/lldb/include/lldb/Utility/RegisterValue.h
index 1ece4f0eb79f7..a0bd493d80941 100644
--- a/lldb/include/lldb/Utility/RegisterValue.h
+++ b/lldb/include/lldb/Utility/RegisterValue.h
@@ -263,8 +263,8 @@ class RegisterValue {
     mutable uint8_t
         bytes[kMaxRegisterByteSize]; // This must be big enough to hold any
                                      // register for any supported target.
-    uint16_t length;
-    lldb::ByteOrder byte_order;
+    uint16_t length = 0;
+    lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
   } buffer;
 };
 

diff  --git a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h
index d869950ab6dd1..86a3a392b348d 100644
--- a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h
+++ b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h
@@ -215,7 +215,7 @@ class StringExtractorGDBRemote : public StringExtractor {
 
 protected:
   ResponseValidatorCallback m_validator = nullptr;
-  void *m_validator_baton;
+  void *m_validator_baton = nullptr;
 };
 
 #endif // LLDB_UTILITY_STRINGEXTRACTORGDBREMOTE_H

diff  --git a/lldb/source/Breakpoint/BreakpointOptions.cpp b/lldb/source/Breakpoint/BreakpointOptions.cpp
index 6fc6948aaccc2..31779fbf693ad 100644
--- a/lldb/source/Breakpoint/BreakpointOptions.cpp
+++ b/lldb/source/Breakpoint/BreakpointOptions.cpp
@@ -115,7 +115,8 @@ BreakpointOptions::BreakpointOptions(bool all_flags_set)
     : m_callback(BreakpointOptions::NullCallback),
       m_baton_is_command_baton(false), m_callback_is_synchronous(false),
       m_enabled(true), m_one_shot(false), m_ignore_count(0),
-      m_condition_text_hash(0), m_auto_continue(false), m_set_flags(0) {
+      m_condition_text_hash(0), m_inject_condition(false),
+      m_auto_continue(false), m_set_flags(0) {
   if (all_flags_set)
     m_set_flags.Set(~((Flags::ValueType)0));
 }
@@ -125,11 +126,9 @@ BreakpointOptions::BreakpointOptions(const char *condition, bool enabled,
                                      bool auto_continue)
     : m_callback(nullptr), m_baton_is_command_baton(false),
       m_callback_is_synchronous(false), m_enabled(enabled),
-      m_one_shot(one_shot), m_ignore_count(ignore),
-      m_condition_text_hash(0), m_auto_continue(auto_continue)
-{
-    m_set_flags.Set(eEnabled | eIgnoreCount | eOneShot 
-                   | eAutoContinue);
+      m_one_shot(one_shot), m_ignore_count(ignore), m_condition_text_hash(0),
+      m_inject_condition(false), m_auto_continue(auto_continue) {
+  m_set_flags.Set(eEnabled | eIgnoreCount | eOneShot | eAutoContinue);
     if (condition && *condition != '\0') {
       SetCondition(condition);
     }
@@ -141,8 +140,8 @@ BreakpointOptions::BreakpointOptions(const BreakpointOptions &rhs)
       m_baton_is_command_baton(rhs.m_baton_is_command_baton),
       m_callback_is_synchronous(rhs.m_callback_is_synchronous),
       m_enabled(rhs.m_enabled), m_one_shot(rhs.m_one_shot),
-      m_ignore_count(rhs.m_ignore_count), m_auto_continue(rhs.m_auto_continue),
-      m_set_flags(rhs.m_set_flags) {
+      m_ignore_count(rhs.m_ignore_count), m_inject_condition(false),
+      m_auto_continue(rhs.m_auto_continue), m_set_flags(rhs.m_set_flags) {
   if (rhs.m_thread_spec_up != nullptr)
     m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
   m_condition_text = rhs.m_condition_text;
@@ -163,6 +162,7 @@ operator=(const BreakpointOptions &rhs) {
     m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
   m_condition_text = rhs.m_condition_text;
   m_condition_text_hash = rhs.m_condition_text_hash;
+  m_inject_condition = rhs.m_inject_condition;
   m_auto_continue = rhs.m_auto_continue;
   m_set_flags = rhs.m_set_flags;
   return *this;

diff  --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 62857c181af89..d034905891bcb 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -201,7 +201,7 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
   }
 
   TargetSP target_sp;
-  LoadScriptFromSymFile load_script_old_value;
+  LoadScriptFromSymFile load_script_old_value = eLoadScriptFromSymFileFalse;
   if (is_load_script && exe_ctx->GetTargetSP()) {
     target_sp = exe_ctx->GetTargetSP();
     load_script_old_value =

diff  --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp
index 0151255631bf8..e9073c84dc0d5 100644
--- a/lldb/source/Core/IOHandlerCursesGUI.cpp
+++ b/lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -588,9 +588,10 @@ class Window : public Surface {
   }
 
   Window(const char *name, const Rect &bounds)
-      : Surface(Surface::Type::Window), m_name(name), m_parent(nullptr),
-        m_subwindows(), m_delegate_sp(), m_curr_active_window_idx(UINT32_MAX),
-        m_prev_active_window_idx(UINT32_MAX), m_delete(true),
+      : Surface(Surface::Type::Window), m_name(name), m_panel(nullptr),
+        m_parent(nullptr), m_subwindows(), m_delegate_sp(),
+        m_curr_active_window_idx(UINT32_MAX),
+        m_prev_active_window_idx(UINT32_MAX), m_delete(false),
         m_needs_update(true), m_can_activate(true), m_is_subwin(false) {
     Reset(::newwin(bounds.size.height, bounds.size.width, bounds.origin.y,
                    bounds.origin.y));
@@ -5702,8 +5703,8 @@ class ValueObjectListDelegate : public WindowDelegate {
   uint32_t m_selected_row_idx = 0;
   uint32_t m_first_visible_row = 0;
   uint32_t m_num_rows = 0;
-  int m_min_x;
-  int m_min_y;
+  int m_min_x = 0;
+  int m_min_y = 0;
   int m_max_x = 0;
   int m_max_y = 0;
 

diff  --git a/lldb/source/Expression/FunctionCaller.cpp b/lldb/source/Expression/FunctionCaller.cpp
index 307bed1ee3fd0..fdbaa918cacbf 100644
--- a/lldb/source/Expression/FunctionCaller.cpp
+++ b/lldb/source/Expression/FunctionCaller.cpp
@@ -44,7 +44,8 @@ FunctionCaller::FunctionCaller(ExecutionContextScope &exe_scope,
       m_function_return_type(return_type),
       m_wrapper_function_name("__lldb_caller_function"),
       m_wrapper_struct_name("__lldb_caller_struct"), m_wrapper_args_addrs(),
-      m_struct_valid(false), m_arg_values(arg_value_list), m_compiled(false),
+      m_struct_valid(false), m_struct_size(0), m_return_size(0),
+      m_return_offset(0), m_arg_values(arg_value_list), m_compiled(false),
       m_JITted(false) {
   m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
   // Can't make a FunctionCaller without a process.

diff  --git a/lldb/source/Expression/LLVMUserExpression.cpp b/lldb/source/Expression/LLVMUserExpression.cpp
index d676608121505..6d11abbf876f4 100644
--- a/lldb/source/Expression/LLVMUserExpression.cpp
+++ b/lldb/source/Expression/LLVMUserExpression.cpp
@@ -48,8 +48,8 @@ LLVMUserExpression::LLVMUserExpression(ExecutionContextScope &exe_scope,
       m_stack_frame_bottom(LLDB_INVALID_ADDRESS),
       m_stack_frame_top(LLDB_INVALID_ADDRESS), m_allow_cxx(false),
       m_allow_objc(false), m_transformed_text(), m_execution_unit_sp(),
-      m_materializer_up(), m_jit_module_wp(), m_can_interpret(false),
-      m_materialized_address(LLDB_INVALID_ADDRESS) {}
+      m_materializer_up(), m_jit_module_wp(), m_target(nullptr),
+      m_can_interpret(false), m_materialized_address(LLDB_INVALID_ADDRESS) {}
 
 LLVMUserExpression::~LLVMUserExpression() {
   if (m_target) {

diff  --git a/lldb/source/Host/common/MainLoop.cpp b/lldb/source/Host/common/MainLoop.cpp
index 8e384c9266b6b..473a3c776436a 100644
--- a/lldb/source/Host/common/MainLoop.cpp
+++ b/lldb/source/Host/common/MainLoop.cpp
@@ -255,7 +255,7 @@ void MainLoop::RunImpl::ProcessEvents() {
 }
 #endif
 
-MainLoop::MainLoop() {
+MainLoop::MainLoop() : m_terminate_request(false) {
 #if HAVE_SYS_EVENT_H
   m_kqueue = kqueue();
   assert(m_kqueue >= 0);

diff  --git a/lldb/source/Interpreter/OptionGroupFormat.cpp b/lldb/source/Interpreter/OptionGroupFormat.cpp
index a2ca9ff398189..f44f82c63b08c 100644
--- a/lldb/source/Interpreter/OptionGroupFormat.cpp
+++ b/lldb/source/Interpreter/OptionGroupFormat.cpp
@@ -37,7 +37,7 @@ OptionGroupFormat::OptionGroupFormat(
     : m_format(default_format, default_format),
       m_byte_size(default_byte_size, default_byte_size),
       m_count(default_count, default_count), m_prev_gdb_format('x'),
-      m_prev_gdb_size('w') {
+      m_prev_gdb_size('w'), m_has_gdb_format(false) {
   // Copy the default option definitions.
   std::copy(std::begin(g_default_option_definitions),
             std::end(g_default_option_definitions),

diff  --git a/lldb/source/Interpreter/OptionGroupVariable.cpp b/lldb/source/Interpreter/OptionGroupVariable.cpp
index 20a521b8e44fe..fb92c51ef79e6 100644
--- a/lldb/source/Interpreter/OptionGroupVariable.cpp
+++ b/lldb/source/Interpreter/OptionGroupVariable.cpp
@@ -67,8 +67,10 @@ static Status ValidateSummaryString(const char *str, void *) {
 }
 
 OptionGroupVariable::OptionGroupVariable(bool show_frame_options)
-    : include_frame_options(show_frame_options), summary(ValidateNamedSummary),
-      summary_string(ValidateSummaryString) {}
+    : include_frame_options(show_frame_options), show_args(false),
+      show_recognized_args(false), show_locals(false), show_globals(false),
+      use_regex(false), show_scope(false), show_decl(false),
+      summary(ValidateNamedSummary), summary_string(ValidateSummaryString) {}
 
 Status
 OptionGroupVariable::SetOptionValue(uint32_t option_idx,


        


More information about the lldb-commits mailing list