aboutsummaryrefslogtreecommitdiffstats
path: root/memisutf8.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--memisutf8.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/memisutf8.c b/memisutf8.c
index 96a8b6b..b477ab8 100644
--- a/memisutf8.c
+++ b/memisutf8.c
@@ -1,5 +1,5 @@
/* See LICENSE file for copyright and license details. */
-#include "libsimple.h"
+#include "common.h"
#ifndef TEST
@@ -11,6 +11,8 @@ libsimple_memisutf8(const char *string, size_t n, int allow_modified_nul)
long int bytes = 0, read_bytes = 0, bits = 0, c, character;
size_t i;
+ character = 0; /* silence false warning from compiler; `character` is set in `if (!read_bytes)` before `else` */
+
/* min bits max bits
0....... 0 7
110..... 10...... 8 11
@@ -36,8 +38,10 @@ libsimple_memisutf8(const char *string, size_t n, int allow_modified_nul)
return 0;
/* Multibyte character. */
- while ((c & 0x80))
- bytes++, c <<= 1;
+ while ((c & 0x80)) {
+ bytes++;
+ c <<= 1;
+ }
read_bytes = 1;
character = (c & 0xFF) >> bytes;
if (bytes > 6)
@@ -59,8 +63,10 @@ libsimple_memisutf8(const char *string, size_t n, int allow_modified_nul)
continue;
/* Check that the character is not unnecessarily long. */
- while (character)
- character >>= 1, bits++;
+ while (character) {
+ character >>= 1;
+ bits++;
+ }
bits = (!bits && bytes == 2 && allow_modified_nul) ? 8 : bits;
if (bits < BYTES_TO_MIN_BITS[bytes] || BYTES_TO_MAX_BITS[bytes] < bits)
return 0;
@@ -85,10 +91,6 @@ main(void)
assert(libsimple_memisutf8(STRING, sizeof(STRING) - 1, i) == (GOOD));\
assert(libsimple_memisutf8(STRING "\xFF", sizeof(STRING) - 1, i) == (GOOD));\
assert(libsimple_memisutf8(STRING "\x00", sizeof(STRING) - 1, i) == (GOOD));\
- assert(libsimple_strisutf8(STRING, i) == (GOOD));\
- assert(libsimple_strnisutf8(STRING, sizeof(STRING) - 1, i) == (GOOD));\
- assert(libsimple_strnisutf8(STRING "\xFF", sizeof(STRING) - 1, i) == (GOOD));\
- assert(libsimple_strnisutf8(STRING "\x00", sizeof(STRING) - 1, i) == (GOOD));\
} while (0)
int i;