fix: string attributes in ShapeInferenceContext

This commit is contained in:
Carson M.
2026-03-20 19:43:49 -05:00
parent 9557b6b03f
commit 85f6074a48

View File

@@ -197,9 +197,9 @@ impl FromOpAttr for String {
where
Self: Sized
{
let mut out = vec![0_u8; len];
ortsys![unsafe ReadOpAttr(attr, ort_sys::OrtOpAttrType::ORT_OP_ATTR_STRING, out.as_mut_ptr().cast(), len, &mut len)?];
debug_assert_eq!(out.len(), len, "int attribute is smaller/larger than expected");
let mut out = vec![0_u8; len + 1];
ortsys![unsafe ReadOpAttr(attr, ort_sys::OrtOpAttrType::ORT_OP_ATTR_STRING, out.as_mut_ptr().cast(), len + 1, &mut len)?];
debug_assert_eq!(out.len(), len + 1, "string attribute is smaller/larger than expected");
CString::from_vec_with_nul(out)
.map_err(|_| Error::new("invalid string attribute contents"))
.and_then(|f| f.into_string().map_err(|_| Error::new("invalid string attribute contents")))