Skip to content

[LLDB][Windows] Initialize read_result#184874

Merged
Nerixyz merged 1 commit intollvm:mainfrom
Nerixyz:fix/lldb-uninit-read
Mar 6, 2026
Merged

[LLDB][Windows] Initialize read_result#184874
Nerixyz merged 1 commit intollvm:mainfrom
Nerixyz:fix/lldb-uninit-read

Conversation

@Nerixyz
Copy link
Contributor

@Nerixyz Nerixyz commented Mar 5, 2026

When I ran lldb -o "b main" -o r, the process crashed at if (!read_result || m_read_pending), because read_result was uninitialized.

As a sidenote: MSVC inserts calls to _RTC_UninitUse which causes a pretty error message when debugging with VS:

Exception has occurred: The variable 'read_result' is being used without being initialized.
Run-Time Check Failure [#]3 - The variable 'read_result' is being used without being initialized.

With LLDB, you get

(lldb) r
Process 12344 stopped
* thread #9, stop reason = Exception 0x80000003 encountered at address 0x7ff96516c96a
       frame #0: 0x00007ff96516c96b liblldb.dll`failwithmessage(retaddr=0x00007ff95742cb02, crttype=1, errnum=3, msg="The variable 'read_result' is being used without being initialized.") at error.cpp:210

We could improve on the stop reason that's displayed.

@Nerixyz Nerixyz requested a review from charles-zablit March 5, 2026 20:11
@Nerixyz Nerixyz requested a review from JDevlieghere as a code owner March 5, 2026 20:12
@llvmbot llvmbot added the lldb label Mar 5, 2026
@llvmbot
Copy link
Member

llvmbot commented Mar 5, 2026

@llvm/pr-subscribers-lldb

Author: Nerixyz (Nerixyz)

Changes

When I ran lldb -o "b main" -o r, the process crashed at if (!read_result || m_read_pending), because read_result was uninitialized.

As a sidenote: MSVC inserts calls to _RTC_UninitUse which causes a pretty error message when debugging with VS:
> Exception has occurred: The variable 'read_result' is being used without being initialized.
> Run-Time Check Failure #3 - The variable 'read_result' is being used without being initialized.

With LLDB, you get

(lldb) r
Process 12344 stopped
* thread #<!-- -->9, stop reason = Exception 0x80000003 encountered at address 0x7ff96516c96a
       frame #<!-- -->0: 0x00007ff96516c96b liblldb.dll`failwithmessage(retaddr=0x00007ff95742cb02, crttype=1, errnum=3, msg="The variable 'read_result' is being used without being initialized.") at error.cpp:210

We could improve on the stop reason that's displayed.


Full diff: https://github.com/llvm/llvm-project/pull/184874.diff

1 Files Affected:

  • (modified) lldb/source/Host/windows/ConnectionGenericFileWindows.cpp (+2-2)
diff --git a/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp b/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp
index c873ce963f535..697c592644cd5 100644
--- a/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp
+++ b/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp
@@ -160,8 +160,8 @@ size_t ConnectionGenericFile::Read(void *dst, size_t dst_len,
   if (!IsConnected())
     return finish(0, eConnectionStatusNoConnection, ERROR_INVALID_HANDLE);
 
-  BOOL read_result;
-  DWORD read_error;
+  BOOL read_result = FALSE;
+  DWORD read_error = ERROR_SUCCESS;
   if (!m_read_pending) {
     m_overlapped.hEvent = m_event_handles[kBytesAvailableEvent];
     read_result = ::ReadFile(m_file, dst, dst_len, NULL, &m_overlapped);

Copy link
Contributor

@charles-zablit charles-zablit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this 👍

@Nerixyz Nerixyz merged commit 119c466 into llvm:main Mar 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants