mirror of
https://git.proxmox.com/git/proxmox-backup-qemu
synced 2025-10-04 22:11:27 +00:00
correctly convert error messages to CString
This commit is contained in:
parent
091e70b0c8
commit
eff15f5748
15
src/lib.rs
15
src/lib.rs
@ -37,9 +37,20 @@ pub extern "C" fn proxmox_backup_free_error(ptr: * mut c_char) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: UTF8 Strings may contain 0 bytes.
|
||||||
|
fn convert_error_to_cstring(err: String) -> CString {
|
||||||
|
match CString::new(err) {
|
||||||
|
Ok(msg) => msg,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("got error containung 0 bytes: {}", err);
|
||||||
|
CString::new("failed to convert error message containing 0 bytes").unwrap()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! raise_error_null {
|
macro_rules! raise_error_null {
|
||||||
($error:ident, $err:expr) => {{
|
($error:ident, $err:expr) => {{
|
||||||
let errmsg = CString::new($err.to_string()).unwrap(); // fixme
|
let errmsg = convert_error_to_cstring($err.to_string());
|
||||||
unsafe { *$error = errmsg.into_raw(); }
|
unsafe { *$error = errmsg.into_raw(); }
|
||||||
return ptr::null_mut();
|
return ptr::null_mut();
|
||||||
}}
|
}}
|
||||||
@ -47,7 +58,7 @@ macro_rules! raise_error_null {
|
|||||||
|
|
||||||
macro_rules! raise_error_int {
|
macro_rules! raise_error_int {
|
||||||
($error:ident, $err:expr) => {{
|
($error:ident, $err:expr) => {{
|
||||||
let errmsg = CString::new($err.to_string()).unwrap(); // fixme
|
let errmsg = convert_error_to_cstring($err.to_string());
|
||||||
unsafe { *$error = errmsg.into_raw(); }
|
unsafe { *$error = errmsg.into_raw(); }
|
||||||
return -1 as c_int;
|
return -1 as c_int;
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user