utf8_nextchar: Don't use a pointed-to variable as a loop counter.

This commit is contained in:
Henrik Rydgård committed 2023-08-17 15:18:24 +02:00
1 parent 07658ef41a
commit 85dbc6b6aa
1 file changed
+5 -3
+5 -3
View File
@@ -219,13 +219,15 @@ int u8_strlen(const char *s)
}
/* reads the next utf-8 sequence out of a string, updating an index */
uint32_t u8_nextchar(const char *s, int *i) {
uint32_t u8_nextchar(const char *s, int *index) {
uint32_t ch = 0;
int sz = 0;
int i = *index;
do {
ch = (ch << 6) + (unsigned char)s[(*i)++];
ch = (ch << 6) + (unsigned char)s[i++];
sz++;
} while (s[*i] && ((s[*i]) & 0xC0) == 0x80);
} while (s[i] && ((s[i]) & 0xC0) == 0x80);
*index = i;
return ch - offsetsFromUTF8[sz - 1];
}