From 045f4bb5b1767140c4f6cfe2d2002553925c4205 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 30 Oct 2024 08:28:15 +0100 Subject: Make string view lengths signed --- lib/cli/optparse.c | 2 +- lib/mbstring/u8chr.c | 2 +- lib/mbstring/u8rchr.c | 2 +- lib/unicode/string/u8gnext.c | 2 +- lib/unicode/string/u8wnext.c | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/cli/optparse.c b/lib/cli/optparse.c index f4034a9..25719f0 100644 --- a/lib/cli/optparse.c +++ b/lib/cli/optparse.c @@ -52,7 +52,7 @@ optparse(optparser_t *st, const cli_opt_t *opts, size_t nopts) const char8_t *eq_p = u8chr(opt, '='); u8view_t opt_no_eq = { .p = opt.p, - .len = eq_p == nullptr ? opt.len : (size_t)(eq_p - opt.p), + .len = eq_p == nullptr ? opt.len : eq_p - opt.p, }; for (size_t i = 0; i < nopts; i++) { diff --git a/lib/mbstring/u8chr.c b/lib/mbstring/u8chr.c index 5ddcdd8..4006ce5 100644 --- a/lib/mbstring/u8chr.c +++ b/lib/mbstring/u8chr.c @@ -79,7 +79,7 @@ u8chr(u8view_t sv, rune ch) char8_t buf[U8_LEN_MAX]; int m = rtou8(buf, sizeof(buf), ch); - if (sv.len < (size_t)m) + if (sv.len < m) return nullptr; switch (m) { case 1: diff --git a/lib/mbstring/u8rchr.c b/lib/mbstring/u8rchr.c index 47eaa4c..0ed9f9e 100644 --- a/lib/mbstring/u8rchr.c +++ b/lib/mbstring/u8rchr.c @@ -69,7 +69,7 @@ u8rchr(u8view_t sv, rune ch) char8_t buf[U8_LEN_MAX]; int n = rtou8(buf, ch, sizeof(buf)); - if (sv.len < (size_t)n) + if (sv.len < n) return nullptr; switch (n) { case 1: diff --git a/lib/unicode/string/u8gnext.c b/lib/unicode/string/u8gnext.c index 7c551f7..6e91cf7 100644 --- a/lib/unicode/string/u8gnext.c +++ b/lib/unicode/string/u8gnext.c @@ -35,7 +35,7 @@ u8gnext(u8view_t *g, u8view_t *sv) for (;;) { rune ch2; - if ((size_t)(p - sv->p) >= sv->len) + if (p - sv->p >= sv->len) ch2 = 0; else m = u8tor(&ch2, p); diff --git a/lib/unicode/string/u8wnext.c b/lib/unicode/string/u8wnext.c index 493ec9f..da11f4a 100644 --- a/lib/unicode/string/u8wnext.c +++ b/lib/unicode/string/u8wnext.c @@ -22,7 +22,7 @@ struct wbrk_state { }; static bool advance(struct wbrk_state *); -static size_t findwbrk(u8view_t); +static ptrdiff_t findwbrk(u8view_t); static struct wbrk_state mkwbrkstate(u8view_t); size_t @@ -34,7 +34,7 @@ u8wnext(u8view_t *w, u8view_t *sv) if (sv->len == 0) return 0; - size_t off = findwbrk(*sv); + ptrdiff_t off = findwbrk(*sv); if (w != nullptr) *w = (u8view_t){sv->p, off}; @@ -43,7 +43,7 @@ u8wnext(u8view_t *w, u8view_t *sv) return off; } -size_t +ptrdiff_t findwbrk(u8view_t sv) { ASSUME(sv.p != nullptr); -- cgit v1.2.3