From: Florian Forster Date: Fri, 22 Dec 2023 14:33:00 +0000 (+0100) Subject: utf8: Iterate over the input string using a for loop. X-Git-Tag: 6.0.0-rc0~22^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0210aa3846e3c173825a022d2a1a05002e38aed9;p=thirdparty%2Fcollectd.git utf8: Iterate over the input string using a for loop. This is arguably easier to read. --- diff --git a/src/utils/utf8/utf8.c b/src/utils/utf8/utf8.c index d5c5f07c7..3ffe6ab6c 100644 --- a/src/utils/utf8/utf8.c +++ b/src/utils/utf8/utf8.c @@ -58,8 +58,9 @@ static void decode(uint32_t *state, uint32_t *codep, uint32_t byte) { bool utf8_valid(char const *s) { uint32_t codepoint, state = 0; - while (*s) - decode(&state, &codepoint, (uint8_t)*s++); + for (size_t i = 0; s[i] != 0; i++) { + decode(&state, &codepoint, (uint8_t)s[i]); + } return state == UTF8_ACCEPT; }