Skip to content

gh-155974: Restore the window attributes when a curses write fails - #155975

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
fedonman:fix-curses-addstr-attr-restore
Aug 20, 2026
Merged

gh-155974: Restore the window attributes when a curses write fails#155975
serhiy-storchaka merged 1 commit into
python:mainfrom
fedonman:fix-curses-addstr-attr-restore

Conversation

@fedonman

@fedonman fedonman commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

addstr(), addnstr(), insstr() and insnstr() now restore the window rendition before reporting a failed write, so a failure no longer leaves the caller's attr applied. A wattrset() failure is still reported when the write itself succeeded.

$ ./python -m test test_curses -u curses -v -m test_output_string_attr_restored
test_output_string_attr_restored (test.test_curses.TestCurses.test_output_string_attr_restored) ... ok
$ ./python -m test test_curses -u curses
Total tests: run=172 skipped=3
Result: SUCCESS

addstr(), addnstr(), insstr() and insnstr() set the window rendition to
the caller's attr, write, then restore the previous rendition.  Since
30dde1e the restore sits below an early return taken when the write
fails, so a failed write leaves the caller's attr on the window and
drops whatever the application had set with attrset().

Restore the rendition first and report the write error afterwards.  A
wattrset() failure is still reported when the write itself succeeded.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 20, 2026
@serhiy-storchaka
serhiy-storchaka merged commit 83531fd into python:main Aug 20, 2026
62 checks passed
@miss-islington-app

Copy link
Copy Markdown

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

@bedevere-app

bedevere-app Bot commented Aug 20, 2026

Copy link
Copy Markdown

GH-156136 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 20, 2026
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.

2 participants