From 736c59125c86343723957298351225f21dbb78b5 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Tue, 26 May 2026 10:34:21 -0400 Subject: [WARP] Fix crash when no default calling convention is registered Fixes https://github.com/Vector35/binaryninja-api/issues/8181 --- plugins/warp/src/convert/types.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/warp/src/convert/types.rs b/plugins/warp/src/convert/types.rs index 6969ac67..93cae0fc 100644 --- a/plugins/warp/src/convert/types.rs +++ b/plugins/warp/src/convert/types.rs @@ -274,13 +274,13 @@ pub fn from_bn_calling_convention(raw_cc: BNRef) -> Calling pub fn to_bn_calling_convention( arch: &A, calling_convention: &CallingConvention, -) -> BNRef { +) -> Option> { for cc in &arch.calling_conventions() { if cc.name().as_str() == calling_convention.name { - return cc.clone(); + return Some(cc.clone()); } } - arch.get_default_calling_convention().unwrap() + None } // Always pass the architecture unless you know what you're doing! @@ -443,9 +443,11 @@ pub fn to_bn_type(arch: Option, ty: &Type) -> BNRef // TODO: Variable arguments let variable_args = false; // If we have a calling convention we run the extended function type creation. - match (c.calling_convention.as_ref(), arch.as_ref()) { - (Some(cc), Some(arch)) => { - let calling_convention = to_bn_calling_convention(arch, cc); + let default_cc = arch.and_then(|a| a.get_default_calling_convention()); + match (c.calling_convention.as_ref(), arch.as_ref(), default_cc) { + (Some(cc), Some(arch), Some(default_cc)) => { + let calling_convention = + to_bn_calling_convention(arch, cc).unwrap_or(default_cc); BNType::function_with_opts( &return_type, ¶ms, @@ -454,7 +456,7 @@ pub fn to_bn_type(arch: Option, ty: &Type) -> BNRef BNConf::new(0, 0), ) } - (_, _) => BNType::function(&return_type, params, variable_args), + (_, _, _) => BNType::function(&return_type, params, variable_args), } } TypeClass::Referrer(c) => { -- cgit v1.3.1