Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle null pointers returned from map_read() #158

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) }
};
Comment on lines +341 to +345
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, there's a rust feature that got stabilized in rust 1.75 that allows us to potentially replace bytes_offet_from with a method in the standard lib (see docs). Similarly for byte_offset.

Those methods don't look like they do any special null handling (playground) so you'd still need this null check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10-4. I'll add it in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nclack Actually it looks like the Mac runners are still on 1.74. Windows and Ubuntu updated only yesterday if you look at the blames. I'll add an issue instead.


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
Loading