From 450a152b240a3d2cfb89a01e92b3a3ce8885d7c2 Mon Sep 17 00:00:00 2001 From: Stephen Marz Date: Thu, 10 Oct 2019 08:45:39 -0400 Subject: [PATCH] Add sanity check from kmalloc. Don't zero if it is null --- risc_v/ch3/src/kmem.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/risc_v/ch3/src/kmem.rs b/risc_v/ch3/src/kmem.rs index 4dd04f0..504076b 100644 --- a/risc_v/ch3/src/kmem.rs +++ b/risc_v/ch3/src/kmem.rs @@ -87,9 +87,11 @@ pub fn kzmalloc(sz: usize) -> *mut u8 { let size = align_val(sz, 3); let ret = kmalloc(size); - for i in 0..size { - unsafe { - (*ret.add(i)) = 0; + if !ret.is_null() { + for i in 0..size { + unsafe { + (*ret.add(i)) = 0; + } } } ret