From 5c080072bc1a7e3e7179fc092700fb1975e0f8d7 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Sat, 8 Nov 2025 02:49:24 -0500 Subject: don't truncate too much; relocate UTF8_* to utf8 section --- vui.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vui.c b/vui.c index a73e15f..7afd974 100644 --- a/vui.c +++ b/vui.c @@ -320,10 +320,6 @@ static void vui_outf(const char *fmt, ...) { * len(cp) = 1 + (0xFFEAA550000 >> (2 * (32 - clz(cp)))) & 3 */ -#define UTF8_CP_LEN_BITS ((uint64_t)0xFFEAA550000) -#define UTF8_CP_SHIFT(cp) ((32 - stdc_leading_zeros((uint32_t)(cp))) << 1) -#define UTF8_CP_LEN(cp) (1 + ((UTF8_CP_LEN_BITS >> UTF8_CP_SHIFT(cp)) & 3)) - static inline void vui_outc(char c) { vui_out_fit(vui_outn + 1); vui_out[vui_outn++] = c; @@ -618,12 +614,12 @@ static void truncate_span(int *x, unsigned *nptr) { *nptr = 0; return; } - if (*x + n >= (int)COLS) { - n = COLS - *x - 1; + if (*x + n > (int)COLS) { + n = COLS - *x; } if (n < 0) n = 0; assert(n >= 0); - assert(*x + n < (int)COLS); + //assert(*x + n < (int)COLS); *nptr = n; } @@ -838,6 +834,10 @@ VuiKey vui_key(void) { /* utf8 */ +#define UTF8_CP_LEN_BITS ((uint64_t)0xFFEAA550000) +#define UTF8_CP_SHIFT(cp) ((32 - stdc_leading_zeros((uint32_t)(cp))) << 1) +#define UTF8_CP_LEN(cp) (1 + ((UTF8_CP_LEN_BITS >> UTF8_CP_SHIFT(cp)) & 3)) + static u32 utf8_decode_len(const char *src, u32 n) { u32 i = 0; u32 len = 0; -- cgit v1.2.3