]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
utf8: Iterate over the input string using a for loop.
authorFlorian Forster <octo@collectd.org>
Fri, 22 Dec 2023 14:33:00 +0000 (15:33 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 28 Dec 2023 08:53:22 +0000 (09:53 +0100)
This is arguably easier to read.

src/utils/utf8/utf8.c

index d5c5f07c7d6f081abd3f8e95e757d69679b55b71..3ffe6ab6c81fe4886ac259e9d05726bea389d670 100644 (file)
@@ -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;
 }