Lost new line character when using ReadFile #20731

Closed
opened 2026-01-31 07:22:28 +00:00 by claunia · 3 comments
Owner

Originally created by @confusedsushi on GitHub (Oct 24, 2023).

Originally assigned to: @lhecker on GitHub.

Windows Terminal version

1.18.2822.0

Windows build number

10.0.22631.2361

Other Software

The problem was first noted in some other console application which is using ReadFile to read from the console. The problem was stripped down to a minimal program

#include <assert.h>
#include <windows.h>

int __cdecl main() {
  char buf[2];
  DWORD read;

  ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf, 2, &read, NULL);
  assert(read == 2);
  assert(buf[0] == '\r');
  assert(buf[1] == '\n');

  ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf, 1, &read, NULL);
  assert(read == 1);
  assert(buf[0] == '\r');

  ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf, 1, &read, NULL);
  assert(read == 1);
  assert(buf[0] == '\n');
}

It seems the unexpected behavior first occurred with https://github.com/microsoft/terminal/pull/14745.

Steps to reproduce

Compile the program using your favorite C compiler and run it. Hit <ENTER> until the example exits.

Expected Behavior

In the good case you have to hit <ENTER> twice and the program exits gracefully.

Actual Behavior

In the bad case you have to hit <ENTER> three times and the last assert fires an error.

Originally created by @confusedsushi on GitHub (Oct 24, 2023). Originally assigned to: @lhecker on GitHub. ### Windows Terminal version 1.18.2822.0 ### Windows build number 10.0.22631.2361 ### Other Software The problem was first noted in some other console application which is using ``ReadFile`` to read from the console. The problem was stripped down to a minimal program ````cpp #include <assert.h> #include <windows.h> int __cdecl main() { char buf[2]; DWORD read; ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf, 2, &read, NULL); assert(read == 2); assert(buf[0] == '\r'); assert(buf[1] == '\n'); ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf, 1, &read, NULL); assert(read == 1); assert(buf[0] == '\r'); ReadFile(GetStdHandle(STD_INPUT_HANDLE), buf, 1, &read, NULL); assert(read == 1); assert(buf[0] == '\n'); } ```` It seems the unexpected behavior first occurred with https://github.com/microsoft/terminal/pull/14745. ### Steps to reproduce Compile the program using your favorite C compiler and run it. Hit ``<ENTER>`` until the example exits. ### Expected Behavior In the good case you have to hit ``<ENTER>`` twice and the program exits gracefully. ### Actual Behavior In the bad case you have to hit ``<ENTER>`` three times and the last assert fires an error.
Author
Owner

@codesculpture commented on GitHub (Jan 24, 2024):

Hey, is this being landed in release ? If yes, in which version

@codesculpture commented on GitHub (Jan 24, 2024): Hey, is this being landed in release ? If yes, in which version
Author
Owner

@DHowett commented on GitHub (Jan 24, 2024):

This is staged for the next 1.18 servicing release! Sorry for the delay.

@DHowett commented on GitHub (Jan 24, 2024): This is staged for the next 1.18 servicing release! Sorry for the delay.
Author
Owner

@Uvaistd24 commented on GitHub (Jan 24, 2024):

@.***

On Wed, 24 Jan 2024 at 06:52 Dustin L. Howett @.***>
wrote:

This is staged for the next 1.18 servicing release! Sorry for the delay.


Reply to this email directly, view it on GitHub
https://github.com/microsoft/terminal/issues/16223#issuecomment-1907308152,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/BEH2LILBOVOFP4KPCGH2SG3YQCAPZAVCNFSM6AAAAAA6NS23UGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBXGMYDQMJVGI
.
You are receiving this because you are subscribed to this thread.Message
ID: @.***>

@Uvaistd24 commented on GitHub (Jan 24, 2024): ***@***.*** On Wed, 24 Jan 2024 at 06:52 Dustin L. Howett ***@***.***> wrote: > This is staged for the next 1.18 servicing release! Sorry for the delay. > > — > Reply to this email directly, view it on GitHub > <https://github.com/microsoft/terminal/issues/16223#issuecomment-1907308152>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/BEH2LILBOVOFP4KPCGH2SG3YQCAPZAVCNFSM6AAAAAA6NS23UGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBXGMYDQMJVGI> > . > You are receiving this because you are subscribed to this thread.Message > ID: ***@***.***> >
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20731