Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lost new line character when using ReadFile #16223

Closed
confusedsushi opened this issue Oct 24, 2023 · 3 comments · Fixed by #16313
Closed

Lost new line character when using ReadFile #16223

confusedsushi opened this issue Oct 24, 2023 · 3 comments · Fixed by #16313
Assignees
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Blocking-Ingestion In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Conhost For issues in the Console codebase

Comments

@confusedsushi
Copy link

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 #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.

@confusedsushi confusedsushi added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Oct 24, 2023
@carlos-zamora carlos-zamora added Product-Conhost For issues in the Console codebase Area-Input Related to input processing (key presses, mouse, etc.) Priority-1 A description (P1) Blocking-Ingestion and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Oct 24, 2023
@carlos-zamora carlos-zamora added this to the Terminal v1.20 milestone Oct 24, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR This issue has a related PR label Nov 15, 2023
microsoft-github-policy-service bot pushed a commit that referenced this issue Nov 21, 2023
This fixes an issue where character-wise reading of an input like "abc"
would return "a" to the caller, store "b" as a partial translation
(= wrong) and return "c" for the caller to store it for the next call.

Closes #16223
Closes #16299

## Validation Steps Performed
* `ReadFile` with a buffer size of 1 returns inputs character by
  character without dropping any inputs ✅

---------

Co-authored-by: Dustin L. Howett <duhowett@microsoft.com>
DHowett added a commit that referenced this issue Dec 4, 2023
This fixes an issue where character-wise reading of an input like "abc"
would return "a" to the caller, store "b" as a partial translation
(= wrong) and return "c" for the caller to store it for the next call.

Closes #16223
Closes #16299

## Validation Steps Performed
* `ReadFile` with a buffer size of 1 returns inputs character by
  character without dropping any inputs ✅

---------

Co-authored-by: Dustin L. Howett <duhowett@microsoft.com>
(cherry picked from commit 63b3820)
Service-Card-Id: 91122022
Service-Version: 1.19
DHowett added a commit that referenced this issue Jan 23, 2024
This fixes an issue where character-wise reading of an input like "abc"
would return "a" to the caller, store "b" as a partial translation
(= wrong) and return "c" for the caller to store it for the next call.

Closes #16223
Closes #16299

## Validation Steps Performed
* `ReadFile` with a buffer size of 1 returns inputs character by
  character without dropping any inputs ✅

---------

Co-authored-by: Dustin L. Howett <duhowett@microsoft.com>
(cherry picked from commit 63b3820)
Service-Card-Id: 91108808
Service-Version: 1.18
@codesculpture
Copy link

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

@DHowett
Copy link
Member

DHowett commented Jan 24, 2024

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

@Uvaistd24

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Blocking-Ingestion In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Conhost For issues in the Console codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants