I am writing a safe wrapper around a c library in rust, and I found a weird behaviour:
// this works
let string = CString::new(filename).expect("error saving image");
let bytes = string.as_bytes_with_nul();
let ptr = bytes.as_ptr();
let image = unsafe { load_image_color(ptr as *mut c_char, width.into(), height.into()) };
//this panics with "STB Reason: can't fopen" as the string passed seems to be null ("")
let string = CString::new(filename)
.expect("error loading image")
.as_bytes_with_nul()
.as_ptr();
let image = unsafe { load_image_color(string as *mut c_char, width.into(), height.into()) };
Can someone please explain to me why these two pieces of code are not semantically equivalent??