summaryrefslogtreecommitdiff
path: root/src/searchutils.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-08-17 10:30:08 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-08-24 00:43:27 -0700
commit2b455da03fb9de9af75fecf5792844a1de108899 (patch)
tree217ef3434af61696d911ffefcf80fafee122743e /src/searchutils.c
parent33b2d2eded9c9679853631ec94825247aae711ac (diff)
downloadgrep-2b455da03fb9de9af75fecf5792844a1de108899.tar.gz
grep: avoid some size_t casts
This helps move the code away from unsigned types. * src/grep.c (buf_has_encoding_errors, contains_encoding_error): * src/searchutils.c (mb_goback): Compare to MB_LEN_MAX, not to (size_t) -2. This is a bit safer anyway, as grep relies on MB_LEN_MAX limits elsewhere. * src/search.h (mb_clen): Compare to -2 before converting to size_t.
Diffstat (limited to 'src/searchutils.c')
-rw-r--r--src/searchutils.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/searchutils.c b/src/searchutils.c
index 80585118..b63990a9 100644
--- a/src/searchutils.c
+++ b/src/searchutils.c
@@ -68,8 +68,8 @@ kwsinit (bool mb_trans)
When returning zero, set *MB_START to CUR. When returning a
positive value, set *MB_START to the next boundary after CUR,
- or to END if there is no such boundary, and set *MBCLEN to the
- length of the preceding character. */
+ or to END if there is no such boundary, and if MBCLEN is nonnull
+ set *MBCLEN to the length of the preceding character. */
ptrdiff_t
mb_goback (char const **mb_start, size_t *mbclen, char const *cur,
char const *end)
@@ -92,7 +92,7 @@ mb_goback (char const **mb_start, size_t *mbclen, char const *cur,
{
mbstate_t mbs = { 0 };
clen = mb_clen (cur - i, end - (cur - i), &mbs);
- if (i < clen && clen < (size_t) -2)
+ if (i < clen && clen <= MB_LEN_MAX)
{
p0 = cur - i;
p = p0 + clen;
@@ -107,7 +107,7 @@ mb_goback (char const **mb_start, size_t *mbclen, char const *cur,
{
clen = mb_clen (p, end - p, &mbs);
- if ((size_t) -2 <= clen)
+ if (MB_LEN_MAX < clen)
{
/* An invalid sequence, or a truncated multibyte character.
Treat it as a single byte character. */