[Lldb-commits] [lldb] [lldb][windows] Fix HostThreadWindows::Join dead-code on GetExitCodeThread failure (PR #199014)
via lldb-commits
lldb-commits at lists.llvm.org
Thu May 21 05:24:37 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Charles Zablit (charles-zablit)
<details>
<summary>Changes</summary>
The old code unconditionally assigned `exit_code` to `*result` after the `GetExitCodeThread` check, so the failure branch assignment of 0 was overwritten. `exit_code` happens to be zero-initialized so the bug was masked, but the structure was wrong.
---
Full diff: https://github.com/llvm/llvm-project/pull/199014.diff
1 Files Affected:
- (modified) lldb/source/Host/windows/HostThreadWindows.cpp (+13-9)
``````````diff
diff --git a/lldb/source/Host/windows/HostThreadWindows.cpp b/lldb/source/Host/windows/HostThreadWindows.cpp
index 4a8843ffdd783..952432d9b5384 100644
--- a/lldb/source/Host/windows/HostThreadWindows.cpp
+++ b/lldb/source/Host/windows/HostThreadWindows.cpp
@@ -31,18 +31,22 @@ HostThreadWindows::~HostThreadWindows() { Reset(); }
void HostThreadWindows::SetOwnsHandle(bool owns) { m_owns_handle = owns; }
Status HostThreadWindows::Join(lldb::thread_result_t *result) {
+ if (!IsJoinable())
+ return Status(ERROR_INVALID_HANDLE, eErrorTypeWin32);
+
Status error;
- if (IsJoinable()) {
- DWORD wait_result = ::WaitForSingleObject(m_thread, INFINITE);
- if (WAIT_OBJECT_0 == wait_result && result) {
+ DWORD wait_result = ::WaitForSingleObject(m_thread, INFINITE);
+ if (wait_result == WAIT_OBJECT_0) {
+ if (result) {
DWORD exit_code = 0;
- if (!::GetExitCodeThread(m_thread, &exit_code))
+ if (::GetExitCodeThread(m_thread, &exit_code))
+ *result = exit_code;
+ else
*result = 0;
- *result = exit_code;
- } else if (WAIT_OBJECT_0 != wait_result)
- error = Status(::GetLastError(), eErrorTypeWin32);
- } else
- error = Status(ERROR_INVALID_HANDLE, eErrorTypeWin32);
+ }
+ } else {
+ error = Status(::GetLastError(), eErrorTypeWin32);
+ }
Reset();
return error;
``````````
</details>
https://github.com/llvm/llvm-project/pull/199014
More information about the lldb-commits
mailing list