From eeb8a893f1f389fb9865ee53cd0c9ecb771a0219 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sun, 23 Nov 2025 12:07:06 -0500 Subject: [PATCH] talk: Rework utf8-awareness in talk_spell() * Eliminates warning on 16-bit unicode devices * More efficient * Still correct Change-Id: I8d29f5560bc6f34b935e867d184a62a280b33596 --- apps/talk.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/apps/talk.c b/apps/talk.c index 7c37121a42..a8ca96463d 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -764,24 +764,15 @@ static int _talk_spell(const char* spell, size_t len, bool enqueue) do_enqueue(enqueue); /* cut off all the pending stuff */ + const char *last = spell; size_t len0 = len - 1; - /* Tokenize into UTF8 codepoints */ while ((spell = utf8decode(spell, &c)), c != '\0') { - int count; - if (c <= 0x7f) - count = 1; - else if (c <= 0x7ff) - count = 2; - else if (c <= 0xffff) - count = 3; - else - count = 4; - - len0 -= count; + len0 -= (spell - last); if (len0 >= len) /* ie we underflow and wrap */ break; + last = spell; /* NOTE: This is COMPLETLY BROKEN for NON-ENGLISH */