Skip to content

gh-156230: Bound a curses window read by the window, not by 2047 - #156282

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:curses-read-clamp
Aug 23, 2026
Merged

gh-156230: Bound a curses window read by the window, not by 2047#156282
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:curses-read-clamp

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 23, 2026

Copy link
Copy Markdown
Member

instr(), in_wstr() and in_wchstr() clamped the count to 2047 and silently truncated a longer line, which a pad can have. A window read cannot return more than the columns left on the line, in the unit each method counts: cells, characters, or bytes at CCHARW_MAX characters of MB_CUR_MAX bytes per cell. Cap the count by that, and read the rest of the line when the count is omitted, which it now can be: n became an optional argument group, so instr([y, x][, n]).

getstr() and get_wstr() read the keyboard rather than the window, so their limit stays.

instr(), in_wstr() and in_wchstr() clamped the count to 2047 and silently
truncated a longer line, which a pad can have.  A window read cannot return
more than the columns left on the line, in the unit each method counts: cells,
characters, or bytes at CCHARW_MAX characters of MB_CUR_MAX bytes per cell.
Cap the count by that, and read the rest of the line when the count is
omitted, which it now can be.

getstr() and get_wstr() read the keyboard rather than the window, so their
limit stays.
Also say what an omitted count means, next to what a specified one means.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34193577 | 📁 Comparing 002fe25 against main (43a1869)

  🔍 Preview build  

2 files changed
± library/curses.html
± whatsnew/changelog.html

@serhiy-storchaka
serhiy-storchaka merged commit ca79981 into python:main Aug 23, 2026
54 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the curses-read-clamp branch August 23, 2026 16:54
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