From: blub Date: Sun, 27 Dec 2009 22:17:13 +0000 (+0000) Subject: with utf8 disabled, u8_byteofs must still behave correctly, also u8_bytelen w/o utf8... X-Git-Tag: xonotic-v0.1.0preview~936 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2b40ee22f7058bbe67b56c8ee656aa209db8d924;p=xonotic%2Fdarkplaces.git with utf8 disabled, u8_byteofs must still behave correctly, also u8_bytelen w/o utf8 should not behave differently git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9712 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/utf8lib.c b/utf8lib.c index c1e5a810..c89ecdfb 100644 --- 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; }