Skip to content

Commit dbbaab1

Browse files
authored
Handle null pointers returned from map_read() (#158)
Fix for the error Micah ran into the other day.
1 parent 32edfd5 commit dbbaab1

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "acquire-imaging"
33
authors = ["Nathan Clack <[email protected]>"]
4-
version = "0.3.0-rc1"
4+
version = "0.3.0-rc2"
55
edition = "2021"
66

77
[lib]

src/runtime.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ impl AvailableDataContext {
338338
} = self;
339339
let stream_id = *stream_id;
340340
let (beg, end) = inner.map_read(stream_id)?;
341-
let nbytes = unsafe { byte_offset_from(beg, end) };
341+
let nbytes = if beg.is_null() || end.is_null() {
342+
0
343+
} else {
344+
unsafe { byte_offset_from(beg, end) }
345+
};
342346

343347
log::trace!(
344348
"[stream {}] ACQUIRED {:p}-{:p}:{} bytes",
@@ -351,13 +355,17 @@ impl AvailableDataContext {
351355
Py::new(
352356
py,
353357
AvailableData {
354-
inner: Arc::new(Mutex::new(Some(RawAvailableData {
355-
runtime: self.inner.clone(),
356-
beg: NonNull::new(beg).ok_or(anyhow!("Expected non-null buffer"))?,
357-
end: NonNull::new(end).ok_or(anyhow!("Expected non-null buffer"))?,
358-
stream_id,
359-
consumed_bytes: None,
360-
}))),
358+
inner: Arc::new(Mutex::new(if nbytes > 0 {
359+
Some(RawAvailableData {
360+
runtime: self.inner.clone(),
361+
beg: NonNull::new(beg).ok_or(anyhow!("Expected non-null buffer"))?,
362+
end: NonNull::new(end).ok_or(anyhow!("Expected non-null buffer"))?,
363+
stream_id,
364+
consumed_bytes: None,
365+
})
366+
} else {
367+
None
368+
})),
361369
},
362370
)
363371
})?;

0 commit comments

Comments
 (0)