[hackers] Re: [[dwm][PATCH]] drw / utf8decode : simpler is better ?

From: <la.luge_AT_free.fr>
Date: Sun, 14 Aug 2022 13:08:46 +0200 (CEST)

Hi,
any response would be welcome.
thank you

----- Mail original -----
De: "nenesses" <la.luge_AT_free.fr>
À: hackers_AT_suckless.org
Cc: "nenesses" <la.luge_AT_free.fr>
Envoyé: Mardi 19 Juillet 2022 16:38:34
Objet: [[dwm][PATCH]] drw / utf8decode : simpler is better ?

---
 drw.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/drw.c b/drw.c
index ced7d37..b6073a4 100644
--- a/drw.c
+++ b/drw.c
_AT_@ -25,16 +25,6 @@ utf8decodebyte(const char c, size_t *i)
 	return 0;
 }
 
-static size_t
-utf8validate(long *u, size_t i)
-{
-	if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
-		*u = UTF_INVALID;
-	for (i = 1; *u > utfmax[i]; ++i)
-		;
-	return i;
-}
-
 static size_t
 utf8decode(const char *c, long *u, size_t clen)
 {
_AT_@ -54,8 +44,9 @@ utf8decode(const char *c, long *u, size_t clen)
 	}
 	if (j < len)
 		return 0;
-	*u = udecoded;
-	utf8validate(u, len);
+
+	*u = (!BETWEEN(udecoded, utfmin[i], utfmax[i]) || BETWEEN(udecoded, 0xD800, 0xDFFF))
+		? UTF_INVALID : udecoded;
 
 	return len;
 }
-- 
2.30.2
Received on Sun Aug 14 2022 - 13:08:46 CEST

This archive was generated by hypermail 2.3.0 : Sun Aug 14 2022 - 13:12:35 CEST