Files
llvm-project/lldb/source/Core/IOHandler.cpp
Jonas Devlieghere c814ac1928 [lldb] Correct use_editline check in IOHandlerEditline (#171733)
Correct the use_editline check in IOHandlerEditline to prevent a crash
when we have an output and/or error file, but no stream. This fixes a
regression introduced by 58279d1 that results in a crash when calling
el_init with a NULL stream.

The original code was checking the stream: GetOutputFILE and
GetErrorFILE.

```
use_editline = GetInputFILE() && GetOutputFILE() && GetErrorFILE() &&
               m_input_sp && m_input_sp->GetIsRealTerminal();
```

The new code is checking the file: `m_output_sp` and `m_error_sp`.

```
use_editline = m_input_sp && m_output_sp && m_error_sp &&
               m_input_sp->GetIsRealTerminal();
```
The correct check is:

```
use_editline =
    m_input_sp && m_input_sp->GetIsRealTerminal() &&
    m_output_sp && m_output_sp->GetUnlockedFile().GetStream() &&
    m_error_sp && m_error_sp->GetUnlockedFile().GetStream();
```

We don't need to update the check for the input, because we're handling
the missing stream there correctly in the call to the constructor:

```
m_editline_up = std::make_unique<Editline>(
    editline_name, m_input_sp ? m_input_sp->GetStream() : nullptr,
    m_output_sp, m_error_sp, m_color);
```

We can't do the same for the output and error because we need to pass
the file, not the stream (to do proper locking).

As I was debugging this I added some more assertions. They're generally
useful so I'm keeping them.

Fixes #170891
2025-12-11 17:24:04 +00:00

21 KiB