WriteConsoleOutput() with 0s produces undefined results instead of clearing like on previous versions #18958

Open
opened 2026-01-31 06:29:42 +00:00 by claunia · 0 comments
Owner

Originally created by @Jimbly on GitHub (Nov 25, 2022).

Windows Terminal version

1.15.2875.0

Windows build number

10.0.22621.819

Other Software

No response

Steps to reproduce

Run a legacy console app that uses WriteConsoleOutput to clear portions of the screen, instead of clearing, results are undefined / timing-dependent and never correct.

Example program:

#include <Windows.h>
#include <stdio.h>

// Expected output:
///  If you can see      there is a bug
// Actual output:
///  If you can see THIS there is a bug
// Output without Sleep():
///  If you can see  there is a bug
int main() {
	HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
	CHAR_INFO blank[4] = { 0 };
	// Workaround if you have access to the original code:
	// 	for (int ii = 0; ii < 4; ii++) {
	// 		blank[ii].Char.AsciiChar = ' ';
	// 	}
	printf("\nIf you can see THIS there is a bug\r");
	Sleep(100); // Without this, the bug is even weirder

	CONSOLE_SCREEN_BUFFER_INFO csbiInfo2;
	GetConsoleScreenBufferInfo(hConsoleOut, &csbiInfo2);
	COORD pos = csbiInfo2.dwCursorPosition;
	SHORT X = pos.X + sizeof("If you can see");
	SMALL_RECT region = { X, pos.Y, csbiInfo2.dwSize.X - 1, pos.Y };
	WriteConsoleOutput(hConsoleOut, blank, { 4, 1 }, { 0, 0 }, &region);
	printf("\n");
}

Expected Behavior

No response

Actual Behavior

Either nothing is written to the screen, or the characters to be overwritten are instead removed from the terminal buffer and everything else shifted over.

Originally created by @Jimbly on GitHub (Nov 25, 2022). ### Windows Terminal version 1.15.2875.0 ### Windows build number 10.0.22621.819 ### Other Software _No response_ ### Steps to reproduce Run a legacy console app that uses WriteConsoleOutput to clear portions of the screen, instead of clearing, results are undefined / timing-dependent and never correct. Example program: ```c #include <Windows.h> #include <stdio.h> // Expected output: /// If you can see there is a bug // Actual output: /// If you can see THIS there is a bug // Output without Sleep(): /// If you can see there is a bug int main() { HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); CHAR_INFO blank[4] = { 0 }; // Workaround if you have access to the original code: // for (int ii = 0; ii < 4; ii++) { // blank[ii].Char.AsciiChar = ' '; // } printf("\nIf you can see THIS there is a bug\r"); Sleep(100); // Without this, the bug is even weirder CONSOLE_SCREEN_BUFFER_INFO csbiInfo2; GetConsoleScreenBufferInfo(hConsoleOut, &csbiInfo2); COORD pos = csbiInfo2.dwCursorPosition; SHORT X = pos.X + sizeof("If you can see"); SMALL_RECT region = { X, pos.Y, csbiInfo2.dwSize.X - 1, pos.Y }; WriteConsoleOutput(hConsoleOut, blank, { 4, 1 }, { 0, 0 }, &region); printf("\n"); } ``` ### Expected Behavior _No response_ ### Actual Behavior Either nothing is written to the screen, or the characters to be overwritten are instead removed from the terminal buffer and everything else shifted over.
claunia added the Issue-BugResolution-Duplicate labels 2026-01-31 06:29:42 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18958