From 9fff3794939bc9892312590759ceb31fad145e03 Mon Sep 17 00:00:00 2001 From: Andrei Homescu Date: Wed, 24 Apr 2024 22:15:48 -0700 Subject: [PATCH] Add an extra null pointer test to analysis example Add one test where a function argument can be either null or non-null in the recur() function of the analysis/tests/misc example code. --- analysis/tests/misc/src/pointers.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/analysis/tests/misc/src/pointers.rs b/analysis/tests/misc/src/pointers.rs index 4d165bfff9..d704a7d14d 100644 --- a/analysis/tests/misc/src/pointers.rs +++ b/analysis/tests/misc/src/pointers.rs @@ -93,6 +93,9 @@ pub unsafe extern "C" fn malloc_wrapper(mut size: size_t) -> *mut libc::c_void { #[no_mangle] pub unsafe extern "C" fn recur(x: libc::c_int, s: *mut S) { if x == 0 { + if s.is_null() { + return; + } return free(s as *mut libc::c_void); } @@ -122,6 +125,7 @@ pub unsafe extern "C" fn simple() { let s = *y; *x = s; recur(3, x); + recur(3, std::ptr::null_mut()); free(x2 as *mut libc::c_void); }