libgrapheme

unicode string library
git clone git://git.suckless.org/libgrapheme
Log | Files | Refs | README | LICENSE

commit d2fe0fa3511539dcb36fe6c678bd14f92d0909d1
parent 227eb47be678aaea70b095048c4d29f82a137d51
Author: Laslo Hunhold <dev@frign.de>
Date:   Sat,  8 Jan 2022 16:49:09 +0100

Consistently use least-types

The fixed-size-types are not guaranteed by the standard to exist.

Signed-off-by: Laslo Hunhold <dev@frign.de>

Diffstat:
Mbenchmark/utf8-decode.c | 2+-
Mbenchmark/util.c | 4++--
Mbenchmark/util.h | 2+-
Msrc/utf8.c | 7++++---
4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/benchmark/utf8-decode.c b/benchmark/utf8-decode.c @@ -67,7 +67,7 @@ main(int argc, char *argv[]) { struct payload p; size_t cpbufsiz, i, off, ret; - uint32_t *cpbuf; + uint_least32_t *cpbuf; double baseline = (double)NAN; (void)argc; diff --git a/benchmark/util.c b/benchmark/util.c @@ -6,11 +6,11 @@ #include "util.h" -uint32_t * +uint_least32_t * generate_test_buffer(const struct test *t, size_t tlen, size_t *bufsiz) { size_t i, j, off; - uint32_t *buf; + uint_least32_t *buf; /* allocate and generate buffer */ for (i = 0, *bufsiz = 0; i < tlen; i++) { diff --git a/benchmark/util.h b/benchmark/util.h @@ -6,7 +6,7 @@ #define LEN(x) (sizeof(x) / sizeof(*(x))) -uint32_t *generate_test_buffer(const struct test *, size_t, size_t *); +uint_least32_t *generate_test_buffer(const struct test *, size_t, size_t *); void run_benchmark(void (*func)(const void *), const void *, const char *, const char *, double *, size_t, size_t); diff --git a/src/utf8.c b/src/utf8.c @@ -8,8 +8,8 @@ /* lookup-table for the types of sequence first bytes */ static const struct { - uint8_t lower; /* lower bound of sequence first byte */ - uint8_t upper; /* upper bound of sequence first byte */ + uint_least8_t lower; /* lower bound of sequence first byte */ + uint_least8_t upper; /* upper bound of sequence first byte */ uint_least32_t mincp; /* smallest non-overlong encoded codepoint */ uint_least32_t maxcp; /* largest encodable codepoint */ /* @@ -191,7 +191,8 @@ grapheme_encode_utf8(uint_least32_t cp, char *str, size_t len) * We do not overwrite the mask because we guaranteed earlier * that there are no bits higher than the mask allows. */ - ((unsigned char *)str)[0] = lut[off].lower | (uint8_t)(cp >> (6 * off)); + ((unsigned char *)str)[0] = lut[off].lower | + (uint_least8_t)(cp >> (6 * off)); for (i = 1; i <= off; i++) { /*