Skip to content

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

Merged
serhiy-storchaka merged 3 commits into
python:mainfrom
serhiy-storchaka:curses-netbsd-innstr
Aug 23, 2026
Merged

gh-154855: Ask non-ncurses curses for one more character#154870
serhiy-storchaka merged 3 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
@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) August 23, 2026 12:15
@serhiy-storchaka
serhiy-storchaka merged commit 43a1869 into python:main Aug 23, 2026
54 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.15 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 43a1869f7eea006f04647d4225d5fda80cb3fbd9 3.15

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 43a1869f7eea006f04647d4225d5fda80cb3fbd9 3.14

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 43a1869f7eea006f04647d4225d5fda80cb3fbd9 3.13

@bedevere-app

bedevere-app Bot commented Aug 23, 2026

Copy link
Copy Markdown

GH-156283 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 23, 2026
@bedevere-app

bedevere-app Bot commented Aug 23, 2026

Copy link
Copy Markdown

GH-156284 is a backport of this pull request to the 3.14 branch.

@bedevere-app

bedevere-app Bot commented Aug 23, 2026

Copy link
Copy Markdown

GH-156285 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Aug 23, 2026
serhiy-storchaka added a commit that referenced this pull request Aug 23, 2026
…54870) (GH-156285)

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() is left as it is.

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.

(cherry picked from commit 43a1869)
serhiy-storchaka added a commit that referenced this pull request Aug 23, 2026
…54870) (GH-156284)

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() is left as it is.

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.

(cherry picked from commit 43a1869)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant