On Sun, Aug 31, 2025 at 02:12:03PM +0200, Benno Schulenberg wrote: > > Hello Thomas, > > In curses/widechar/charable.c there is this fragment of code: > > ... > char temp[MB_LEN_MAX]; > > result = wctomb(temp, ch); > > if (strlen(temp) == 1) > ...
ah... I've exercised the wctob for quite a while. In a quick check, none of the machines for which I have build-logs except for FreeBSD 4.9 (in a build from 2012) lacked that function. NCURSES_EXPORT(int) _nc_to_char(wint_t ch) { int result; #if HAVE_WCTOB result = wctob(ch); #elif HAVE_WCTOMB char temp[MB_LEN_MAX]; result = wctomb(temp, ch); if (strlen(temp) == 1) result = UChar(temp[0]); else result = -1; #else #error expected either wctob/wctomb #endif return result; } Just so I know - what's the platform? (If you're talking about musl, I won't be surprised -- but realistically, I'll test this area by disabling the HAVE_WCTOB and running valgrind) > But wctomb() does not nul-terminate the string of bytes produced in > `temp`, so calling strlen() on it does not give the number of these > bytes. Nor is there any need for it -- `result` already contains > that number. > > Patch is attached. (But if it were up to me, I would elide the entire > `result` variable.) > > > Benno > > --- ncurses/widechar/charable.c.was 2025-08-31 13:49:27.510832095 +0200 > +++ ncurses/widechar/charable.c 2025-08-31 13:50:15.294242167 +0200 > @@ -54,7 +54,7 @@ > #elif HAVE_WCTOMB > char temp[MB_LEN_MAX]; > result = wctomb(temp, ch); > - if (strlen(temp) == 1) > + if (result == 1) > result = UChar(temp[0]); > else > result = -1; -- Thomas E. Dickey <dic...@invisible-island.net> https://invisible-island.net
signature.asc
Description: PGP signature