Skip to content

Commit

Permalink
Handle null pointers returned from map_read() (#158)
Browse files Browse the repository at this point in the history
Fix for the error Micah ran into the other day.
  • Loading branch information
aliddell authored Jan 10, 2024
1 parent 32edfd5 commit dbbaab1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "acquire-imaging"
authors = ["Nathan Clack <[email protected]>"]
version = "0.3.0-rc1"
version = "0.3.0-rc2"
edition = "2021"

[lib]
Expand Down
24 changes: 16 additions & 8 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ impl AvailableDataContext {
} = self;
let stream_id = *stream_id;
let (beg, end) = inner.map_read(stream_id)?;
let nbytes = unsafe { byte_offset_from(beg, end) };
let nbytes = if beg.is_null() || end.is_null() {
0
} else {
unsafe { byte_offset_from(beg, end) }
};

log::trace!(
"[stream {}] ACQUIRED {:p}-{:p}:{} bytes",
Expand All @@ -351,13 +355,17 @@ impl AvailableDataContext {
Py::new(
py,
AvailableData {
inner: Arc::new(Mutex::new(Some(RawAvailableData {
runtime: self.inner.clone(),
beg: NonNull::new(beg).ok_or(anyhow!("Expected non-null buffer"))?,
end: NonNull::new(end).ok_or(anyhow!("Expected non-null buffer"))?,
stream_id,
consumed_bytes: None,
}))),
inner: Arc::new(Mutex::new(if nbytes > 0 {
Some(RawAvailableData {
runtime: self.inner.clone(),
beg: NonNull::new(beg).ok_or(anyhow!("Expected non-null buffer"))?,
end: NonNull::new(end).ok_or(anyhow!("Expected non-null buffer"))?,
stream_id,
consumed_bytes: None,
})
} else {
None
})),
},
)
})?;
Expand Down

0 comments on commit dbbaab1

Please sign in to comment.