[Lldb-commits] [lldb] [LLDB][SBProgress] Fix bad optional access in sbprogress (PR #128971)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Feb 26 15:54:13 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Jacob Lalonde (Jlalond)
<details>
<summary>Changes</summary>
This fixes the obvious, but untested case of sending None/Null to SBProgress. This was an oversight on my part.
---
Full diff: https://github.com/llvm/llvm-project/pull/128971.diff
2 Files Affected:
- (modified) lldb/source/API/SBProgress.cpp (+4-1)
- (modified) lldb/test/API/python_api/sbprogress/TestSBProgress.py (+12)
``````````diff
diff --git a/lldb/source/API/SBProgress.cpp b/lldb/source/API/SBProgress.cpp
index e67e289a60eff..d40e11da973d4 100644
--- a/lldb/source/API/SBProgress.cpp
+++ b/lldb/source/API/SBProgress.cpp
@@ -40,7 +40,10 @@ SBProgress::~SBProgress() = default;
void SBProgress::Increment(uint64_t amount, const char *description) {
LLDB_INSTRUMENT_VA(amount, description);
- m_opaque_up->Increment(amount, description);
+ std::optional<std::string> description_opt;
+ if (description && description[0])
+ description_opt = description;
+ m_opaque_up->Increment(amount, description_opt);
}
lldb_private::Progress &SBProgress::ref() const { return *m_opaque_up; }
diff --git a/lldb/test/API/python_api/sbprogress/TestSBProgress.py b/lldb/test/API/python_api/sbprogress/TestSBProgress.py
index c456247da80c6..5f7820a5bd81e 100644
--- a/lldb/test/API/python_api/sbprogress/TestSBProgress.py
+++ b/lldb/test/API/python_api/sbprogress/TestSBProgress.py
@@ -33,3 +33,15 @@ def test_without_external_bit_set(self):
expected_string = "Test progress first increment"
progress.Increment(1, expected_string)
self.assertFalse(listener.PeekAtNextEvent(event))
+
+ def test_with_external_bit_set(self):
+ """Test SBProgress can handle null events."""
+
+ progress = lldb.SBProgress("Test SBProgress", "Test progress", self.dbg)
+ listener = lldb.SBListener("Test listener")
+ broadcaster = self.dbg.GetBroadcaster()
+ broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgress)
+ event = lldb.SBEvent()
+
+ progress.Increment(1, None)
+ self.assertTrue(listener.PeekAtNextEvent(event))
``````````
</details>
https://github.com/llvm/llvm-project/pull/128971
More information about the lldb-commits
mailing list