Skip to content

gh-154855: Ask non-ncurses curses for one more character - #154870

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:curses-netbsd-innstr
Open

gh-154855: Ask non-ncurses curses for one more character#154870
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:curses-netbsd-innstr

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

instr(), in_wstr() and in_wchstr() pass n to the library, which is ncurses' reading of n: it stores n characters and adds a terminator. NetBSD curses counts the terminator in n, so these methods return one character too few there. X/Open does not settle the point: "at most n bytes in the string", with no mention of a terminator.

Such a library is asked for n + 1, and the read is repeated for the requested length if it stored more than asked -- truncating could split a multibyte character. That is not possible for input, where the extra character is consumed and echoed before we see it, so getstr() and get_wstr() are left as they are.

instr() now takes the length from the value returned by winnstr(), as X/Open specifies, like in_wstr() since GH-154782.

Against NetBSD 10.1 native curses (--with-curses=curses), test_curses goes from 34 failures to 22, with nothing newly broken. Builds against ncurses are unchanged, the macro being 0; forcing it to 1 there makes 12 tests fail without the repeated read and pass with it.

Passing n to the library is ncurses' reading of n: it stores n characters
and adds a terminator.  NetBSD curses counts the terminator in n.

Ask a library that is neither ncurses nor PDCurses for n + 1, and read
again if it stored more than asked; truncating could split a multibyte
character.  This is not possible for input, so getstr() and get_wstr() are
left as they are.

instr() now takes the length from the value returned by winnstr(), as
X/Open specifies, instead of searching for a terminator which it does not.
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant