diff --git a/firmware/common/unicode.c b/firmware/common/unicode.c old mode 100644 new mode 100755 index 61989e5..c31c146 --- a/firmware/common/unicode.c +++ b/firmware/common/unicode.c @@ -313,9 +313,19 @@ unsigned long utf8length(const unsigned char *utf8) { unsigned long l = 0; + if (!*utf8) + return 0; + while (*utf8 != 0) if ((*utf8++ & MASK) != COMP) l++; + + /* + * When 0x80 <= *utf8 <= 0xbf (for all bytes). + * It is an illegal UTF-8 string. + */ + if (l == 0) + return 1; return l; }