
* Add rawmemchr * Add stpncpy * Add strchrnul * Fix strcat * Added strncat * Add wcschr * Minor tweak * Add wcsncmp * Add wcsnlen * Add wcsrchr * Add wmemchr * Fix asan load/store sizes for wide string functions * Refactor patches * Rename tracking functions to prevent collision with allocator * Change return type of asan_sym to make it consistent with the other native functions * Fix mutex re-entrancy issue in Patches by splitting locks * Fix tests on 32-bit platforms --------- Co-authored-by: Your Name <you@example.com>
52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
#[cfg(test)]
|
|
#[cfg(feature = "hooks")]
|
|
mod tests {
|
|
use core::{
|
|
ffi::{c_int, c_void},
|
|
ptr::null_mut,
|
|
};
|
|
|
|
use asan::{expect_panic, hooks::rawmemchr::rawmemchr};
|
|
|
|
#[test]
|
|
fn test_rawmemchr_null_buffer() {
|
|
expect_panic();
|
|
unsafe { rawmemchr(null_mut(), 0) };
|
|
unreachable!()
|
|
}
|
|
|
|
#[test]
|
|
fn test_rawmemchr_find_first() {
|
|
let data = "abcdefghij".as_bytes();
|
|
let c = 'a' as c_int;
|
|
let ret = unsafe { rawmemchr(data.as_ptr() as *const c_void, c) };
|
|
assert_eq!(ret, data.as_ptr() as *mut c_void);
|
|
}
|
|
|
|
#[test]
|
|
fn test_rawmemchr_find_last() {
|
|
let data = "abcdefghij".as_bytes();
|
|
let c = 'j' as c_int;
|
|
let ret = unsafe { rawmemchr(data.as_ptr() as *const c_void, c) };
|
|
assert_eq!(ret, unsafe {
|
|
data.as_ptr().add(data.len() - 1) as *mut c_void
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn test_rawmemchr_find_mid() {
|
|
let data = "abcdefghij".as_bytes();
|
|
let c = 'e' as c_int;
|
|
let ret = unsafe { rawmemchr(data.as_ptr() as *const c_void, c) };
|
|
assert_eq!(ret, unsafe { data.as_ptr().add(4) as *mut c_void });
|
|
}
|
|
|
|
#[test]
|
|
fn test_rawmemchr_find_repeated() {
|
|
let data = "ababababab".as_bytes();
|
|
let c = 'b' as c_int;
|
|
let ret = unsafe { rawmemchr(data.as_ptr() as *const c_void, c) };
|
|
assert_eq!(ret, unsafe { data.as_ptr().add(1) as *mut c_void });
|
|
}
|
|
}
|