From 2b40ee22f7058bbe67b56c8ee656aa209db8d924 Mon Sep 17 00:00:00 2001 From: blub Date: Sun, 27 Dec 2009 22:17:13 +0000 Subject: [PATCH] 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 --- utf8lib.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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; } -- 2.39.2