summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2019-03-13 11:22:56 +0000
committerschwarze <schwarze@openbsd.org>2019-03-13 11:22:56 +0000
commit6b13d5955afabb313d9440f1ba6db4abea5ef528 (patch)
tree2a033421cbbaad8703bdb591186612d717eecde4
parentBackport support for probing ARMv8 HW acceleration capabilities on armv7 (diff)
downloadwireguard-openbsd-6b13d5955afabb313d9440f1ba6db4abea5ef528.tar.xz
wireguard-openbsd-6b13d5955afabb313d9440f1ba6db4abea5ef528.zip
UTF-8 cleanup in do_append() replacing calls to broken functions:
* get_wchar() -> mbtowc(3) * is_composing_char() || is_combining_char() -> wcwidth(3) * control_char() -> !isprint(3) * is_ubin_char() -> !iswprint(3) OK millert@
-rw-r--r--usr.bin/less/line.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/usr.bin/less/line.c b/usr.bin/less/line.c
index 01c7ede581d..78bbda7b927 100644
--- a/usr.bin/less/line.c
+++ b/usr.bin/less/line.c
@@ -16,6 +16,7 @@
*/
#include <wchar.h>
+#include <wctype.h>
#include "charset.h"
#include "less.h"
@@ -774,8 +775,8 @@ retry:
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 @@ do_append(LWCHAR ch, char *rep, off_t pos)
*/
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 @@ do_append(LWCHAR ch, char *rep, off_t pos)
} 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 @@ do_append(LWCHAR ch, char *rep, off_t pos)
}
/* 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 @@ do_append(LWCHAR ch, char *rep, off_t pos)
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 @@ do_control_char:
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);