memchr_inv() takes a size_t length but counts 8 byte words in an
unsigned int. At 32GiB that count wraps, so the scan can quietly miss
most of the range.

Use size_t for the word count.

Fixes: 798248206b59 ("lib/string.c: introduce memchr_inv()")
Signed-off-by: Bradley Morgan <[email protected]>
---
 lib/string.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/string.c b/lib/string.c
index 1f9297e9776a..8ea7d4b9f0c0 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -837,7 +837,8 @@ void *memchr_inv(const void *start, int c, size_t bytes)
 {
        u8 value = c;
        u64 value64;
-       unsigned int words, prefix;
+       size_t words;
+       unsigned int prefix;
 
        if (bytes <= 16)
                return check_bytes8(start, value, bytes);
-- 
2.53.0


Reply via email to