From d64555a566ae75617d4e9d147b43219229be3b4f Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Tue, 20 Aug 2024 16:17:06 +0200 Subject: [PATCH] Fix a crash when disabling the ASB --- src/host/_stream.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/host/_stream.cpp b/src/host/_stream.cpp index e434e413ebd..82dda40ef9b 100644 --- a/src/host/_stream.cpp +++ b/src/host/_stream.cpp @@ -336,6 +336,9 @@ void WriteCharsVT(SCREEN_INFORMATION& screenInfo, const std::wstring_view& str) { auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); auto& stateMachine = screenInfo.GetStateMachine(); + // If the given screenInfo is the alternate screen buffer, disabling the alternate screen buffer in this + // VT payload will cause the pointer to be invalidated. We thus need to get all the information we need now. + const auto disableNewlineTranslation = WI_IsFlagSet(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN); // When switch between the main and alt-buffer SCREEN_INFORMATION::GetActiveBuffer() // may change, so get the VtIo reference now, just in case. auto writer = gci.GetVtWriterForBuffer(&screenInfo); @@ -350,7 +353,7 @@ void WriteCharsVT(SCREEN_INFORMATION& screenInfo, const std::wstring_view& str) // DISABLE_NEWLINE_AUTO_RETURN not being set is equivalent to a LF -> CRLF translation. const auto write = [&](size_t beg, size_t end) { const auto chunk = til::safe_slice_abs(str, beg, end); - if (WI_IsFlagSet(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN)) + if (disableNewlineTranslation) { writer.WriteUTF16(chunk); }