Skip to content

gh-154874: Fix the sign of curses.termattrs() - #154875

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-curses-termattrs-sign
Open

gh-154874: Fix the sign of curses.termattrs()#154875
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-curses-termattrs-sign

Conversation

@fedonman

@fedonman fedonman commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

termattrs() returns a chtype mask, but GH-134327 routed it through an int to check
for ERR. On a terminal that advertises A_ITALIC, the topmost bit of a 32-bit mask,
the result comes back negative and the attribute functions reject it:

>>> curses.termattrs()
-2130771968
>>> curses.term_attrs()          # the same bits, unsigned
2164195328
>>> curses.newwin(1, 1).attrset(curses.termattrs())
OverflowError: can't convert negative value to unsigned int

It now returns the mask unsigned, the same way getattrs(), slk_attr() and
term_attrs() already do. baudrate(), the macro's only other user, really does return
a status, so it keeps the ERR check.

The test drives newterm('xterm-256color') over a pseudo-terminal rather than using
$TERM, which on CI is usually linux and advertises no italic, so a signed result
would slip through. It fails without the change.

3.15 has the same bug, so this needs a backport. 3.14 is fine.

termattrs() returns a chtype mask, but it was routed through an int, so a
terminal that advertises A_ITALIC came back negative and the result could
no longer be passed to the attribute functions.
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