]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
with utf8 disabled, u8_byteofs must still behave correctly, also u8_bytelen w/o utf8...
authorblub <blub@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 27 Dec 2009 22:17:13 +0000 (22:17 +0000)
committerblub <blub@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 27 Dec 2009 22:17:13 +0000 (22:17 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9712 d7cf8633-e32d-0410-b094-e92efae38249

utf8lib.c

index c1e5a81000c635537687d7ed1edf858b6edc6d5b..c89ecdfb8f9fbe4d699b8fbed09e50bfba6b8dc2 100644 (file)
--- a/utf8lib.c
+++ b/utf8lib.c
@@ -222,8 +222,10 @@ size_t u8_bytelen(const char *_s, size_t n)
        size_t len = 0;
        const unsigned char *s = (const unsigned char*)_s;
 
-       if (!utf8_enable.integer)
-               return n;
+       if (!utf8_enable.integer) {
+               len = strlen(_s);
+               return (len < n) ? len : n;
+       }
 
        while (*s && n)
        {
@@ -267,6 +269,12 @@ int u8_byteofs(const char *_s, size_t i, size_t *len)
 
        if (!utf8_enable.integer)
        {
+               if (strlen(_s) < i)
+               {
+                       if (len) *len = 0;
+                       return -1;
+               }
+
                if (len) *len = 1;
                return i;
        }