Improve FFI error message handling

This commit is contained in:
Oliver Hamlet
2025-04-28 17:48:20 +01:00
parent dbbbcd58e5
commit b45ace0700
+3 -2
View File
@@ -16,8 +16,9 @@ use crate::state::{plugin_crc, plugin_version};
pub(crate) fn error(code: c_int, message: &str) -> c_int {
ERROR_MESSAGE.with(|f| {
*f.borrow_mut() =
CString::new(message.as_bytes()).unwrap_or(c"Failed to retrieve error message".into());
*f.borrow_mut() = CString::new(message.as_bytes())
.or_else(|_e| CString::new(message.replace('\0', "\\0").as_bytes()))
.unwrap_or_else(|_e| c"Failed to retrieve error message".into());
});
code
}