]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Fix u8_COM_StringLengthNoColors not counting many ASCII chars (up to '?')
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 4 Sep 2010 15:32:06 +0000 (15:32 +0000)
committerRudolf Polzer <divverent@alientrap.org>
Sat, 4 Sep 2010 15:34:07 +0000 (17:34 +0200)
Better handling of invalid chars in u8_COM_StringLengthNoColors

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10438 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=f0eda58867febcd4dc0f6c6be401d37000d136c5

utf8lib.c

index 151a1ca5b90f39b95bcdae64906c78597c341505..3a2fabe79da7fb6dd4542dad468a1fa9512180f4 100644 (file)
--- a/utf8lib.c
+++ b/utf8lib.c
@@ -682,6 +682,7 @@ u8_COM_StringLengthNoColors(const char *_s, size_t size_s, qboolean *valid)
        const unsigned char *s = (const unsigned char*)_s;
        const unsigned char *end;
        size_t len = 0;
+       size_t bits = 0;
 
        if (!utf8_enable.integer)
                return COM_StringLengthNoColors(_s, size_s, valid);
@@ -734,13 +735,14 @@ u8_COM_StringLengthNoColors(const char *_s, size_t size_s, qboolean *valid)
                }
 
                // start of a wide character
-               if (*s & 0xC0)
+               bits = utf8_lengths[*s];
+               if (bits >= 2)
                {
-                       for (++s; *s >= 0x80 && *s <= 0xC0; ++s);
+                       for (++s; bits >= 1 && *s >= 0x80 && *s < 0xC0; ++s, --bits);
                        continue;
                }
-               // part of a wide character, we ignore that one
-               if (*s <= 0xBF)
+               // part of a wide character or invalid character, we ignore that one
+               if (bits == 0)
                        --len;
                ++s;
        }