libgrapheme

Freestanding C library for unicode string handling
git clone https://git.sinitax.com/suckless/libgrapheme
Log | Files | Refs | README | LICENSE | sfeed.txt

commit cb7e9c00899ae0ed57a84991308b7f880f4ddef6
parent 4483b44e8444d4a57bcbb31dbe9eac3e6b80c1ad
Author: Laslo Hunhold <dev@frign.de>
Date:   Sat, 18 Dec 2021 20:21:04 +0100

Use SIZE_MAX instead of (size_t)-1

This makes a bit clearer what we mean, and given the library is C99
we can rely on this constant to exist.

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

Diffstat:
Mman/grapheme_decode_utf8.3 | 6+++---
Msrc/character.c | 6+++---
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/man/grapheme_decode_utf8.3 b/man/grapheme_decode_utf8.3 @@ -31,8 +31,8 @@ Given NUL has a unique 1 byte representation, it is safe to operate on NUL-terminated strings by setting .Va len to -.Dv (size_t)-1 -and terminating when +.Dv SIZE_MAX +(stdint.h is already included by grapheme.h) and terminating when .Va cp is 0 (see .Sx EXAMPLES @@ -87,7 +87,7 @@ print_cps_nul_terminated(const char *str) uint_least32_t cp; for (off = 0; (ret = grapheme_decode_utf8(str + off, - (size_t)-1, &cp)) > 0 && + SIZE_MAX, &cp)) > 0 && cp != 0; off += ret) { printf("%"PRIxLEAST32"\\n", cp); } diff --git a/src/character.c b/src/character.c @@ -197,19 +197,19 @@ grapheme_next_character_break(const char *str) * miss it, even if the previous UTF-8 sequence terminates * unexpectedly, as it would either act as an unexpected byte, * saved for later, or as a null byte itself, that we can catch. - * We pass (size_t)-1 to the length, as we will never read beyond + * We pass SIZE_MAX to the length, as we will never read beyond * the null byte for the reasons given above. */ /* get first codepoint */ - len += grapheme_decode_utf8(str, (size_t)-1, &cp0); + len += grapheme_decode_utf8(str, SIZE_MAX, &cp0); if (cp0 == GRAPHEME_INVALID_CODEPOINT) { return len; } while (cp0 != 0) { /* get next codepoint */ - ret = grapheme_decode_utf8(str + len, (size_t)-1, &cp1); + ret = grapheme_decode_utf8(str + len, SIZE_MAX, &cp1); if (cp1 == GRAPHEME_INVALID_CODEPOINT || grapheme_is_character_break(cp0, cp1, &state)) {