diff --git a/src/strings/src/lib.rs b/src/strings/src/lib.rs index 34df1cbdefb300942d25ecbd733d13223928e939..5737face2672b56f676866a52f58253287e0976a 100644 --- a/src/strings/src/lib.rs +++ b/src/strings/src/lib.rs @@ -109,10 +109,13 @@ pub unsafe extern "C" fn strcasecmp(mut first: *const c_char, mut second: *const } first = first.offset(1); - second = first.offset(1); + second = second.offset(1); } - // Both strings ended at the same time too - (*first == *second) as c_int + // Both strings didn't end with NUL bytes + if *first != *second { + return -1; + } + 0 } #[no_mangle] pub unsafe extern "C" fn strncasecmp( @@ -136,9 +139,12 @@ pub unsafe extern "C" fn strncasecmp( } first = first.offset(1); - second = first.offset(1); + second = second.offset(1); n -= 1; } - // Both strings ended at the same time too - (n == 0 || *first == *second) as c_int + // Both strings didn't end with NUL bytes (unless we reached the limit) + if n != 0 && *first != *second { + return -1; + } + 0 } diff --git a/src/sys_socket/cbindgen.toml b/src/sys_socket/cbindgen.toml index dee4af3bed10dcd2b2d9035c1fd6e2b709450d66..0e830717c19f5eece263d145b3edbf4ba3aa4607 100644 --- a/src/sys_socket/cbindgen.toml +++ b/src/sys_socket/cbindgen.toml @@ -1,4 +1,4 @@ -sys_includes = ["stddef.h", "sys/types.h"] +sys_includes = ["stddef.h", "stdint.h", "sys/types.h"] include_guard = "_SYS_SOCKET_H" style = "Tag" language = "C" diff --git a/tests/strings.c b/tests/strings.c index 2423b900371d949a27cf0283e56c42d29dbbd90c..3f43175c7804f33eb39c8cdc80ded18028e71da1 100644 --- a/tests/strings.c +++ b/tests/strings.c @@ -11,8 +11,8 @@ int main() { bcopy("hi", new, 3); // include nul byte assert(!strcasecmp("hi", new)); - assert(!strcasecmp("hi", "HI")); - assert(!strncasecmp("hi", "HIHI", 2)); + assert(!strcasecmp("hello", "HEllO")); + assert(!strncasecmp("hello", "Hello World", 5)); bzero(new, 1); assert(*new == 0);