You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
curses cell text is silently truncated at an embedded NUL #155877
curses.complexchar() keeps only the text before an embedded NUL, so complexchar('a\0\u0301') silently drops the combining acute, and complexchar('\0') builds a cell with no text at all, whose repr() is not a valid constructor call.
curses.complexchar('a')
curses.complexchar('á')
curses.complexchar('')
Traceback (most recent call last):
File "/tmp/bug.py", line 7, in <module>
eval(r, {'curses': curses})
~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 1, in <module>
TypeError: expect a string of 1 to 5 characters, got a str of length 0
The empty cell is worse than the truncation: window.addstr(curses.complexstr([curses.complexchar('\0'), curses.complexchar('B')])) returns None having written nothing. The same text reaches the same converter through window.addch(), insch(), echochar(), hline(), vline(), bkgd(), bkgdset(), border() and box(), and curses.complexstr('a\0b') drops the NUL and returns two cells.
Expected: ValueError: embedded null character, which window.addstr('a\0b') already raises.
complexchar('\0') can be read back by in_wch(). This is why it should be supported. It is more complex for complexstr with embedded NUL. I have not found function which can return it: in_wstr() and instr() skip NUL, in_wchstr() truncates on NUL. And the output functions vary in their handling of NUL too. So it is safe to reject embedded NUL in complexstr. Other option -- allow embedded NUL in complexstr, but reject it at write time instead.
Activity
serhiy-storchaka commentedon Aug 16, 2026
addch('\0')was always accepted (it is equivalent toaddch(0)), so I thinkaddch(complexchar('\0'))should work the same way.The repr for empty cell is
complexchar('\0')in the narrow build, it should be the same in the wide build.Silent truncation after embedded NUL is not good, we try to detect such errors.
serhiy-storchaka commentedon Aug 21, 2026
complexchar('\0')can be read back byin_wch(). This is why it should be supported. It is more complex forcomplexstrwith embedded NUL. I have not found function which can return it:in_wstr()andinstr()skip NUL,in_wchstr()truncates on NUL. And the output functions vary in their handling of NUL too. So it is safe to reject embedded NUL incomplexstr. Other option -- allow embedded NUL incomplexstr, but reject it at write time instead.gh-155877: Fix a NUL in a curses character cell (GH-156158)
serhiy-storchaka commentedon Aug 21, 2026
Thank you for your reports and fixes @fedonman.