Unsupported casts to void are a major source of analysis failures on lighttpd. In many of these cases, the resulting void is passed to memcpy or a similar libc function. Most of these have a straightforward safe replacement that eliminates the cast:
memset(dest as *mut c_void, 0, n) (where dest: *mut P and P is a primitive type) => dest[..n].fill(0) (where dest: &mut [P])
memcmp(a as *const c_void, b as *const c_void, n) (where a: *const u8 and b: *const u8) => a[..n].cmp(&b[..n]) as c_int (where a: &[u8] and b: &[u8])
memchr(a as *const c_void, c, n) (where a: *const u8) => a[..n].iter().position(|&x| == c).map_or(ptr::null(), |i| &a[i..]) (where a: &[u8]). Note memchr returns a pointer to the matching byte rather than an integer index.
Similar rewrites apply for non-slice pointers, such as *dest = (*src).clone() for memcpy.
Unsupported casts to void are a major source of analysis failures on lighttpd. In many of these cases, the resulting void is passed to
memcpy
or a similar libc function. Most of these have a straightforward safe replacement that eliminates the cast:memcpy(dest as *mut c_void, src as *const c_void, n)
(wheredest: *mut T
,src: *const T
) =>dest[..n].clone_from_slice(&src[..n])
(wheredest: &mut [T]
,src: &[T]
)memset(dest as *mut c_void, 0, n)
(wheredest: *mut P
andP
is a primitive type) =>dest[..n].fill(0)
(wheredest: &mut [P]
)memcmp(a as *const c_void, b as *const c_void, n)
(wherea: *const u8
andb: *const u8
) =>a[..n].cmp(&b[..n]) as c_int
(wherea: &[u8]
andb: &[u8]
)memchr(a as *const c_void, c, n)
(wherea: *const u8
) =>a[..n].iter().position(|&x| == c).map_or(ptr::null(), |i| &a[i..])
(wherea: &[u8]
). Notememchr
returns a pointer to the matching byte rather than an integer index.Similar rewrites apply for non-slice pointers, such as
*dest = (*src).clone()
formemcpy
.