From 059df3782fb3c01a9545799c2a3a248fdfe4e5ed Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Thu, 19 Dec 2024 18:34:25 +0200 Subject: [PATCH] unicode: Explicitly set INT_MAX for unlimited utf8_size -1 could be supplied unintentionally from user code when utf8_size is computable value Fixup for 004304dc and 1f548f74 Change-Id: I93008ea289bdb134f051975c25b0db9d0e64b823 --- firmware/common/unicode.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/firmware/common/unicode.c b/firmware/common/unicode.c index b740967227..d2ec07df0a 100644 --- a/firmware/common/unicode.c +++ b/firmware/common/unicode.c @@ -280,15 +280,12 @@ unsigned char* utf8encode(unsigned long ucs, unsigned char *utf8) unsigned char* iso_decode(const unsigned char *iso, unsigned char *utf8, int cp, int count) { - return iso_decode_ex(iso, utf8, cp, count, -1); + return iso_decode_ex(iso, utf8, cp, count, INT_MAX); } /* Recode an iso encoded string to UTF-8 */ unsigned char* iso_decode_ex(const unsigned char *iso, unsigned char *utf8, int cp, int count, int utf8_size) { - if (utf8_size == -1) - utf8_size = INT_MAX; - uint16_t *table = NULL; cp_lock_enter(); @@ -423,9 +420,6 @@ unsigned char* iso_decode_ex(const unsigned char *iso, unsigned char *utf8, int unsigned char* utf16decode(const unsigned char *utf16, unsigned char *utf8, int count, int utf8_size, bool le) { - if (utf8_size == -1) - utf8_size = INT_MAX; - // little-endian flag is used as significant byte index if (le) le = 1; @@ -453,13 +447,13 @@ unsigned char* utf16decode(const unsigned char *utf16, unsigned char *utf8, unsigned char* utf16LEdecode(const unsigned char *utf16, unsigned char *utf8, int count) { - return utf16decode(utf16, utf8, count, -1, true); + return utf16decode(utf16, utf8, count, INT_MAX, true); } unsigned char* utf16BEdecode(const unsigned char *utf16, unsigned char *utf8, int count) { - return utf16decode(utf16, utf8, count, -1, false); + return utf16decode(utf16, utf8, count, INT_MAX, false); } bool utf16_has_bom(const unsigned char *utf16, bool *le)