lib: memscan() fixlet
authorAlexey Dobriyan <adobriyan@gmail.com>
Thu, 1 Jul 2021 01:56:01 +0000 (18:56 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 1 Jul 2021 18:06:05 +0000 (11:06 -0700)
Generic version doesn't trucate second argument to char.

Older brother memchr() does as do s390, sparc and i386 assembly versions.

Fortunately, no code passes c >= 256.

Link: https://lkml.kernel.org/r/YLv4cCf0t5UPdyK+@localhost.localdomain
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/string.c

index 7548eb715ddbf2bfc463a47a9aec819ee28b5cad..77bd0b1d32967c92a30c70df9afceb244587d0e5 100644 (file)
@@ -977,7 +977,7 @@ void *memscan(void *addr, int c, size_t size)
        unsigned char *p = addr;
 
        while (size) {
-               if (*p == c)
+               if (*p == (unsigned char)c)
                        return (void *)p;
                p++;
                size--;