=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/line.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- src/usr.bin/less/line.c 2019/03/12 11:59:24 1.27 +++ src/usr.bin/less/line.c 2019/03/13 11:22:56 1.28 @@ -16,6 +16,7 @@ */ #include +#include #include "charset.h" #include "less.h" @@ -774,8 +775,8 @@ static int do_append(LWCHAR ch, char *rep, off_t pos) { + wchar_t prev_ch; int a; - LWCHAR prev_ch; a = AT_NORMAL; @@ -813,7 +814,10 @@ */ overstrike = utf_mode ? -1 : 0; /* To be correct, this must be a base character. */ - prev_ch = get_wchar(linebuf + curr); + if (mbtowc(&prev_ch, linebuf + curr, MB_CUR_MAX) == -1) { + (void)mbtowc(NULL, NULL, MB_CUR_MAX); + prev_ch = L'\0'; + } a = attr[curr]; if (ch == prev_ch) { /* @@ -835,7 +839,7 @@ } else { a |= AT_BOLD; } - } else if (ch == '_') { + } else if (ch == '_' && prev_ch != L'\0') { a |= AT_UNDERLINE; ch = prev_ch; rep = linebuf + curr; @@ -844,8 +848,7 @@ } /* Else we replace prev_ch, but we keep its attributes. */ } else if (overstrike < 0) { - if (is_composing_char(ch) || - is_combining_char(get_wchar(linebuf + curr), ch)) { + if (wcwidth(ch) == 0) { /* Continuation of the same overstrike. */ if (curr > 0) a = attr[curr - 1] & (AT_UNDERLINE | AT_BOLD); @@ -868,7 +871,8 @@ return (1); break; } - } else if ((!utf_mode || is_ascii_char(ch)) && control_char((char)ch)) { + } else if ((!utf_mode || is_ascii_char(ch)) && + !isprint((unsigned char)ch)) { do_control_char: if (ctldisp == OPT_ON || (ctldisp == OPT_ONPLUS && ch == ESC)) { @@ -881,7 +885,7 @@ if (store_prchar(ch, pos)) return (1); } - } else if (utf_mode && ctldisp != OPT_ON && is_ubin_char(ch)) { + } else if (utf_mode && ctldisp != OPT_ON && !iswprint(ch)) { char *s; s = prutfchar(ch);