aboutsummaryrefslogtreecommitdiffstats
path: root/memisutf8.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-06-11 16:37:09 +0200
committerMattias Andrée <maandree@kth.se>2022-06-11 16:37:09 +0200
commitfcfe59c1f2219408ac2a9cd84b386816ff252221 (patch)
tree0f46c009babfba2d0200ece3ecce067c548a66b6 /memisutf8.c
parentRemove `static` from some `static inline` (diff)
downloadlibsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.gz
libsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.bz2
libsimple-fcfe59c1f2219408ac2a9cd84b386816ff252221.tar.xz
Fix warnings, replace some static inline with inline + extern inline, and fix glibc support
Diffstat (limited to '')
-rw-r--r--memisutf8.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/memisutf8.c b/memisutf8.c
index 96a8b6b..b3d321e 100644
--- a/memisutf8.c
+++ b/memisutf8.c
@@ -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;