acpi_tables: add a safety comment for the write function

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2022-11-16 17:14:33 +00:00 committed by Liu Wei
parent 3d08a0fba9
commit 1d9050dbe3

View File

@ -98,6 +98,7 @@ impl Sdt {
/// Write a value at the given offset
pub fn write<T>(&mut self, offset: usize, value: T) {
assert!((offset + (std::mem::size_of::<T>() - 1)) < self.data.len());
// SAFETY: The assertion above makes sure we don't do out of bounds write.
unsafe {
*(((self.data.as_mut_ptr() as usize) + offset) as *mut T) = value;
}