Skip to content

gh-69573: Check return value of msvcrt_putch and msvcrt_putwch - #155956

Open
imabd645 wants to merge 2 commits into
python:mainfrom
imabd645:fix-msvcrt-putch-69573
Open

gh-69573: Check return value of msvcrt_putch and msvcrt_putwch#155956
imabd645 wants to merge 2 commits into
python:mainfrom
imabd645:fix-msvcrt-putch-69573

Conversation

@imabd645

@imabd645 imabd645 commented Aug 17, 2026

Copy link
Copy Markdown

Description

This PR fixes a longstanding bug in the msvcrt module where the return values of the underlying Windows _putch and _putwch functions were ignored.

According to the Windows C Runtime documentation, these functions return EOF (or WEOF) when an error occurs (such as when the console is unattached or output is redirected improperly). Because the Python wrappers (msvcrt.putch and msvcrt.putwch) previously returned None unconditionally, these errors were silently swallowed.

Changes:

  • Added a check for EOF in msvcrt_putch_impl.
  • Added a check for WEOF in msvcrt_putwch_impl.
  • If an error is detected, they now correctly raise an OSError via PyErr_SetFromErrno(PyExc_OSError).
  • Added the corresponding NEWS blurb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant