From 85dbc6b6aa8cf7bf3feed001946e86ad49a26c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 17 Aug 2023 15:18:24 +0200 Subject: [PATCH] utf8_nextchar: Don't use a pointed-to variable as a loop counter. --- Common/Data/Encoding/Utf8.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Common/Data/Encoding/Utf8.cpp b/Common/Data/Encoding/Utf8.cpp index 82567948cf..fb3e829d16 100644 --- a/Common/Data/Encoding/Utf8.cpp +++ b/Common/Data/Encoding/Utf8.cpp @@ -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]; }