summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2020-01-08 14:40:52 +0000
committernicm <nicm>2020-01-08 14:40:52 +0000
commit36eb16ce7db2db71b510964a2e453e6b349b03f0 (patch)
tree1385a410bb4e67d463b476dc6bc83a2fd98679e3
parent6628e542b5a0fabbd02800e68d19aecaf530fece (diff)
Do not hang in format_trim_* on invalid UTF-8 characters.
-rw-r--r--format-draw.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/format-draw.c b/format-draw.c
index 6cced9fd..bb16e0dd 100644
--- a/format-draw.c
+++ b/format-draw.c
@@ -849,8 +849,10 @@ format_trim_left(const char *expanded, u_int limit)
out += ud.size;
}
width += ud.width;
- } else
+ } else {
cp -= ud.have;
+ cp++;
+ }
} else if (*cp > 0x1f && *cp < 0x7f) {
if (width + 1 <= limit)
*out++ = *cp;
@@ -896,8 +898,10 @@ format_trim_right(const char *expanded, u_int limit)
out += ud.size;
}
width += ud.width;
- } else
+ } else {
cp -= ud.have;
+ cp++;
+ }
} else if (*cp > 0x1f && *cp < 0x7f) {
if (width >= skip)
*out++ = *cp;