Skip to content

Commit 14c4e43

Browse files
authored
Double-check size of returned blob dimensions (#58)
As discussed [here], this change adds a (perhaps overkill) safety check of the size of the dimensions array returned by the OpenVINO library. The added assertion is trying to avoid the improbable case where some future version of the OpenVINO library returns a dimensions array with size different than the one auto-generated in the bindings; see `struct dimensions` in `openvino-sys/src/generated/types.rs`. [here]: #56 (comment)
1 parent e5e2cc1 commit 14c4e43

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

crates/openvino/src/blob.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ impl Blob {
5858

5959
let mut dimensions = MaybeUninit::uninit();
6060
try_unsafe!(ie_blob_get_dims(blob, dimensions.as_mut_ptr()))?;
61+
// Safety: this assertion is trying to avoid the improbable case where some future version
62+
// of the OpenVINO library returns a dimensions array with size different than the one
63+
// auto-generated in the bindings; see `struct dimensions` in
64+
// `openvino-sys/src/generated/types.rs`. It is not clear to me whether this will return the
65+
// statically-expected size or the dynamic size -- this is not effective in the former case.
66+
assert_eq!(unsafe { dimensions.assume_init() }.dims.len(), 8);
6167

6268
let mut precision = MaybeUninit::uninit();
6369
try_unsafe!(ie_blob_get_precision(blob, precision.as_mut_ptr()))?;

0 commit comments

Comments
 (0)