Hi
On Sun, Apr 03, 2011 at 11:34:54PM +0200, Stefan Sperling wrote:
> The upcoming diff to make wcwidth() return -1 for non-printable
> characters might have funny effects for these callers in libcurses.
>
> Index: base/lib_addstr.c
> ===================================================================
> RCS file: /cvs/src/lib/libcurses/base/lib_addstr.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 lib_addstr.c
> --- base/lib_addstr.c 12 Jan 2010 23:22:05 -0000 1.5
> +++ base/lib_addstr.c 3 Apr 2011 21:24:19 -0000
> @@ -182,7 +182,7 @@ wadd_wchnstr(WINDOW *win, const cchar_t
>
> len = wcwidth(CharOf(astr[i]));
>
> - if (x + len - 1 <= win->_maxx) {
> + if (len >= 0 && x + len - 1 <= win->_maxx) {
Not sure this is required, astr is a cchar_t * which will come from
setcchar.
> line->text[x] = _nc_render(win, astr[i]);
> if (len > 1) {
> for (j = 0; j < len; ++j) {
> Index: base/lib_slkset.c
> ===================================================================
> RCS file: /cvs/src/lib/libcurses/base/lib_slkset.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 lib_slkset.c
> --- base/lib_slkset.c 12 Jan 2010 23:22:06 -0000 1.4
> +++ base/lib_slkset.c 3 Apr 2011 21:26:04 -0000
> @@ -83,6 +83,7 @@ slk_set(int i, const char *astr, int for
> mbstate_t state;
> wchar_t wc;
> size_t need;
> + int w;
>
> init_mb(state);
> need = mbrtowc(0, p, strlen(p), &state);
> @@ -91,9 +92,12 @@ slk_set(int i, const char *astr, int for
> mbrtowc(&wc, p, need, &state);
> if (!iswprint((wint_t) wc))
> break;
> - if (wcwidth(wc) + numcols > limit)
> + w = wcwidth(wc);
> + if (w >= 0) {
> + if (w + numcols > limit)
> break;
> - numcols += wcwidth(wc);
> + numcols += w;
> + }
Doesn't iswprint() make this unnecessary?
> p += need;
> }
> numchrs = (p - str);
> Index: widechar/lib_cchar.c
> ===================================================================
> RCS file: /cvs/src/lib/libcurses/widechar/lib_cchar.c,v
> retrieving revision 1.1
> diff -u -p -r1.1 lib_cchar.c
> --- widechar/lib_cchar.c 6 Sep 2010 17:26:17 -0000 1.1
> +++ widechar/lib_cchar.c 3 Apr 2011 21:28:19 -0000
> @@ -73,7 +73,7 @@ setcchar(cchar_t *wcval,
> * are only interested in adding non-spacing characters.
> */
> for (i = 1; i < len; ++i) {
> - if (wcwidth(wch[i]) != 0) {
> + if (wcwidth(wch[i]) >= 1) {
This seems sane although the comment at the top of the function says "we
assume" this cannot happen.
> len = i;
> break;
> }