Investigate why the COOKED_READ_DATA ctor takes a string_view for wchar_t data? #7763

Open
opened 2026-01-31 01:12:05 +00:00 by claunia · 0 comments
Owner

Originally created by @zadjii-msft on GitHub (Apr 28, 2020).

COOKED_READ_DATA takes an initialData parameter of a string_view
d6cae40d26/src/host/readDataCooked.cpp (L46-L54)

However, when it memcpy's it, it copies it as a wchar_t buffer:
d6cae40d26/src/host/readDataCooked.cpp (L97-L103)

As you can see here, _bufPtr is a wchar_t* which is initialized to _bufPtr = reinterpret_cast<wchar_t*>(_buffer.get())
d6cae40d26/src/host/readDataCooked.hpp (L124-L136)

As I'm writing tests that use some cooked read data for #1856, I'm finding that the string I'm initializing the cooked read with is getting horribly mangled, because I'm passing a char buffer in.

Why is it like this? Does this magically just normally work when users call ReadConsole with wchar_t data in the buffer? I couldn't really figure it out in just a morning, so I'm filing this to make sure to follow up.

The test in question is ConptyRoundtripTests::TestResizeWithCookedRead.

Originally created by @zadjii-msft on GitHub (Apr 28, 2020). `COOKED_READ_DATA` takes an `initialData` parameter of a `string_view` https://github.com/microsoft/terminal/blob/d6cae40d26d2f4ba249d3960e8478c04681c8e1e/src/host/readDataCooked.cpp#L46-L54 However, when it `memcpy`'s it, it copies it as a `wchar_t` buffer: https://github.com/microsoft/terminal/blob/d6cae40d26d2f4ba249d3960e8478c04681c8e1e/src/host/readDataCooked.cpp#L97-L103 As you can see here, `_bufPtr` is a `wchar_t*` which is initialized to `_bufPtr = reinterpret_cast<wchar_t*>(_buffer.get())` https://github.com/microsoft/terminal/blob/d6cae40d26d2f4ba249d3960e8478c04681c8e1e/src/host/readDataCooked.hpp#L124-L136 As I'm writing tests that use some cooked read data for #1856, I'm finding that the string I'm initializing the cooked read with is getting horribly mangled, because I'm passing a `char` buffer in. Why is it like this? Does this magically just normally work when users call `ReadConsole` with `wchar_t` data in the buffer? I couldn't really figure it out in just a morning, so I'm filing this to make sure to follow up. The test in question is `ConptyRoundtripTests::TestResizeWithCookedRead`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7763