From 4f77fa3d96c465edb9cbd5d890291bc092c506fe Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Thu, 4 Apr 2024 19:52:03 +1100 Subject: [PATCH] Ensure precondition is met when using slice::from_raw_parts --- crates/pindakaas/src/solver/libloading.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/pindakaas/src/solver/libloading.rs b/crates/pindakaas/src/solver/libloading.rs index 1a471c00e..0c378dfd1 100644 --- a/crates/pindakaas/src/solver/libloading.rs +++ b/crates/pindakaas/src/solver/libloading.rs @@ -375,7 +375,11 @@ pub(crate) unsafe extern "C" fn ipasir_check_model_cb( model: *const i32, ) -> bool { let prop = &mut *(state as *mut IpasirPropStore); - let sol = std::slice::from_raw_parts(model, len); + let sol = if len > 0 { + std::slice::from_raw_parts(model, len) + } else { + &[] + }; let sol: std::collections::HashMap = sol .iter() .map(|&i| (Var(NonZeroI32::new(i.abs()).unwrap()), i >= 0))