Skip to content

Commit 8f55382

Browse files
authored
ByteAddressableBuffer fixes (#179)
* ByteAddressableBuffer: fix debug printf mispile, segfaulting debug printf validation layer * ByteAddressableBuffer: fix oob calculation thinking all buffers are only `len / 4` long
1 parent d9dba91 commit 8f55382

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

crates/spirv-std/src/byte_addressable_buffer.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,12 @@ fn bounds_check<T>(data: &[u32], byte_index: u32) {
7070
if byte_index % 4 != 0 {
7171
panic!("`byte_index` should be a multiple of 4");
7272
}
73-
if byte_index + sizeof > data.len() as u32 {
74-
let last_byte = byte_index + sizeof;
73+
let last_byte = byte_index + sizeof;
74+
let len = data.len() as u32 * 4;
75+
if byte_index + sizeof > len {
7576
panic!(
7677
"index out of bounds: the len is {} but loading {} bytes at `byte_index` {} reads until {} (exclusive)",
77-
data.len(),
78-
sizeof,
79-
byte_index,
80-
last_byte,
78+
len, sizeof, byte_index, last_byte,
8179
);
8280
}
8381
}

0 commit comments

Comments
 (0)