From: blub Date: Fri, 25 Dec 2009 16:50:12 +0000 (+0000) Subject: u8_get{n,}char should advance the end-ptr even if no valid character was found so... X-Git-Tag: xonotic-v0.1.0preview~957 X-Git-Url: http://de.git.xonotic.org/?a=commitdiff_plain;h=e68da68713dfb19c88e7c639348b604b3c480b47;hp=b580442d0be79e1c4c78b9cb568fe30cf3e03f76;p=xonotic%2Fdarkplaces.git u8_get{n,}char should advance the end-ptr even if no valid character was found so it at least points to the \0 or to after maxlen git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9691 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/utf8lib.c b/utf8lib.c index 5f46832a..3e1d62fa 100644 --- a/utf8lib.c +++ b/utf8lib.c @@ -45,15 +45,16 @@ findchar: //fprintf(stderr, "skipping\n"); ++i; } - if(i >= _maxlen) - return false; - //fprintf(stderr, "checking\n"); + //fprintf(stderr, "checking\n"); // If we hit the end, well, we're out and invalid - if (!s[i]) + if(i >= _maxlen || !s[i]) { + if (_start) *_start = i; + if (_len) *_len = 0; return false; - //fprintf(stderr, "checking ascii\n"); + } + //fprintf(stderr, "checking ascii\n"); // ascii characters if (s[i] < 0x80) { @@ -76,8 +77,11 @@ findchar: ++i; goto findchar; } - if(i + bits > _maxlen) + if(i + bits > _maxlen) { + if (_start) *_start = i; + if (_len) *_len = 0; return false; + } // turn bt into a mask and give ch a starting value --bt; ch = (s[i] & bt); @@ -436,7 +440,7 @@ Uchar u8_getchar(const char *_s, const char **_end) } if (!u8_analyze(_s, &st, &ln, &ch, U8_ANALYZE_INFINITY)) - return 0; + ch = 0; if (_end) *_end = _s + st + ln; return ch; @@ -466,7 +470,7 @@ Uchar u8_getnchar(const char *_s, const char **_end, size_t _maxlen) } if (!u8_analyze(_s, &st, &ln, &ch, _maxlen)) - return 0; + ch = 0; if (_end) *_end = _s + st + ln; return ch;