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
PDC_wcstombs() zeroes the first byte when the output exactly fills the buffer (regression in ea9baa42) #390
Since ea9baa4 ("PDC_wcstombs() now returns a null-terminated string if it hits an un-encodeable wide character or runs out of buffer space", #384), PDC_wcstombs() treats an output that exactly fills the buffer as an error and overwrites its first byte:
size_ti=wcstombs(dest, src, n);
...
assert( -1!= (int)i&&i<n);
if( (int)i<0||i >= n) /* invalid sequence or insufficient space */*dest='\0';
elsedest[i] ='\0';
wcstombs() returns n when the converted string fills all n bytes; that is a complete conversion, not a failure, and the previous code handled it by writing the terminator at dest[n]. Now a converted string is destroyed in the common case, and in a build with assertions enabled the assert fails and the program aborts.
winnstr() hits this on every call, since it converts n wide characters into n bytes:
wgetnstr() is affected the same way, so with a wide build every instr()/getstr() of single-byte text comes back with a NUL first byte (CPython's test_curses shows b'\x00BCDE' for instr() and b'' for getstr(); it passes against d226010).
A second problem is how the failure is detected: i is a size_t and wcstombs() reports an error as (size_t)-1, so (int)i < 0 (and -1 != (int)i in the assert) relies on implementation-defined narrowing, and would also reject a valid result above INT_MAX. The check should be i == (size_t)-1. Since wcstombs() never returns more than n, that is the only case that needs *dest = '\0':
You beat me to it. I noticed trouble because my 'fix' caused an assertion to be triggered in the 'Output Test' part of testcurs, which appears to be the only demo/test that uses winnstr(). Will investigate (and probably just pull in your fix)... thank you!
Activity
Bill-Gray commentedon Sep 15, 2026
You beat me to it. I noticed trouble because my 'fix' caused an assertion to be triggered in the 'Output Test' part of
testcurs, which appears to be the only demo/test that useswinnstr(). Will investigate (and probably just pull in your fix)... thank you!New beep 'scheduling' scheme to avoid overlapping beeps without using…