linux-stable/tools/include/nolibc
Rasmus Villemoes b3f4f51ea6 tools/nolibc/string: Fix memcmp() implementation
The C standard says that memcmp() must treat the buffers as consisting
of "unsigned chars". If char happens to be unsigned, the casts are ok,
but then obviously the c1 variable can never contain a negative
value. And when char is signed, the casts are wrong, and there's still
a problem with using an 8-bit quantity to hold the difference, because
that can range from -255 to +255.

For example, assuming char is signed, comparing two 1-byte buffers,
one containing 0x00 and another 0x80, the current implementation would
return -128 for both memcmp(a, b, 1) and memcmp(b, a, 1), whereas one
of those should of course return something positive.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Fixes: 66b6f755ad ("rcutorture: Import a copy of nolibc")
Cc: stable@vger.kernel.org # v5.0+
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
2022-10-28 15:07:02 -07:00
..
arch-aarch64.h tools/nolibc: Remove .global _start from the entry point code 2022-04-20 17:05:46 -07:00
arch-arm.h tools/nolibc: Remove .global _start from the entry point code 2022-04-20 17:05:46 -07:00
arch-i386.h tools/nolibc: i386: Implement syscall with 6 arguments 2022-04-20 17:05:46 -07:00
arch-mips.h tools/nolibc: Remove .global _start from the entry point code 2022-04-20 17:05:46 -07:00
arch-riscv.h tools/nolibc: make argc 32-bit in riscv startup code 2022-08-31 05:17:43 -07:00
arch-x86_64.h tools/nolibc: Remove .global _start from the entry point code 2022-04-20 17:05:46 -07:00
arch.h tools/nolibc/arch: split arch-specific code into individual files 2022-04-20 17:05:43 -07:00
ctype.h tools/nolibc/ctype: add the missing is* functions 2022-04-20 17:05:43 -07:00
errno.h tools/nolibc/errno: extract errno.h from sys.h 2022-04-20 17:05:45 -07:00
Makefile tools/nolibc: add a help target to list supported targets 2022-06-20 09:43:19 -07:00
nolibc.h tools/nolibc: also mention how to build by just setting the include path 2022-04-20 17:05:45 -07:00
signal.h tools/nolibc/signal: move raise() to signal.h 2022-04-20 17:05:45 -07:00
std.h tools/nolibc/std: move the standard type definitions to std.h 2022-04-20 17:05:33 -07:00
stdio.h tools/nolibc/stdio: Add format attribute to enable printf warnings 2022-06-20 09:43:19 -07:00
stdlib.h tools/nolibc/stdlib: Support overflow checking for older compiler versions 2022-06-20 09:43:19 -07:00
string.h tools/nolibc/string: Fix memcmp() implementation 2022-10-28 15:07:02 -07:00
sys.h tools/nolibc: make sys_mmap() automatically use the right __NR_mmap definition 2022-08-31 05:17:43 -07:00
time.h tools/nolibc/time: create time.h with time() 2022-04-20 17:05:45 -07:00
types.h tools/nolibc/types: Implement offsetof() and container_of() macro 2022-04-20 17:05:46 -07:00
unistd.h tools/nolibc/unistd: add usleep() 2022-04-20 17:05:45 -07:00