diff --git a/core-helper.c b/core-helper.c index f75155465..76fa720b1 100644 --- a/core-helper.c +++ b/core-helper.c @@ -1415,6 +1415,18 @@ uint64_t stress_get_uint64_zero(void) return g_shared->zero; } +/* + * stress_get_uint64_zero() + * return null in way that force less smart + * static analysers to realise we are doing this + * to force a division by zero. I'd like to have + * a better solution than this ghastly way. + */ +void *stress_get_null(void) +{ + return (void *)g_shared->zero; +} + /* * stress_base36_encode_uint64() * encode 64 bit hash of filename into a unique base 36 diff --git a/core-helper.h b/core-helper.h index e6866254f..cd7dbb958 100644 --- a/core-helper.h +++ b/core-helper.h @@ -77,6 +77,7 @@ extern WARN_UNUSED int stress_strcmp_munged(const char *s1, const char *s2); extern WARN_UNUSED ssize_t stress_get_stack_direction(void); extern WARN_UNUSED void *stress_get_stack_top(void *start, size_t size); extern WARN_UNUSED uint64_t stress_get_uint64_zero(void); +extern WARN_UNUSED void *stress_get_null(void); extern int stress_temp_filename(char *path, const size_t len, const char *name, const pid_t pid, const uint32_t instance, const uint64_t magic); extern int stress_temp_filename_args(stress_args_t *args, char *path, diff --git a/stress-mlock.c b/stress-mlock.c index ae22ec610..0841607e3 100644 --- a/stress-mlock.c +++ b/stress-mlock.c @@ -217,10 +217,10 @@ static void stress_mlock_misc(stress_args_t *args, const size_t page_size, const VOID_RET(int, shim_munlock((void *)(~(uintptr_t)0 & ~(page_size - 1)), page_size << 1)); VOID_RET(int, shim_mlock((void *)0, ~(size_t)0)); - VOID_RET(int, munlock((void *)stress_get_uint64_zero(), ~(size_t)0)); + VOID_RET(int, munlock((void *)stress_get_null(), ~(size_t)0)); VOID_RET(int, shim_mlock((void *)0, 0)); - VOID_RET(int, munlock((void *)stress_get_uint64_zero(), 0)); + VOID_RET(int, munlock((void *)stress_get_null(), 0)); #if defined(HAVE_MLOCKALL) { diff --git a/stress-mmap.c b/stress-mmap.c index 4cd1343a3..a61a8be24 100644 --- a/stress-mmap.c +++ b/stress-mmap.c @@ -712,8 +712,8 @@ static int stress_mmap_child(stress_args_t *args, void *ctxt) /* * Step #6, invalid unmappings */ - (void)munmap(NULL, 0); - (void)munmap(NULL, ~(size_t)0); + (void)munmap(stress_get_null(), 0); + (void)munmap(stress_get_null(), ~(size_t)0); /* * Step #7, random choice from any of the valid/invalid diff --git a/stress-schedpolicy.c b/stress-schedpolicy.c index 5c18b5424..2cf218afa 100644 --- a/stress-schedpolicy.c +++ b/stress-schedpolicy.c @@ -278,7 +278,7 @@ static int stress_schedpolicy(stress_args_t *args) #if defined(__linux__) /* Linux allows NULL param, will return EFAULT */ (void)shim_memset(¶m, 0, sizeof(param)); - VOID_RET(int, sched_getparam(pid, NULL)); + VOID_RET(int, sched_getparam(pid, stress_get_null())); #endif /* Exercise bad pid, ESRCH error */ @@ -291,7 +291,7 @@ static int stress_schedpolicy(stress_args_t *args) #if defined(__linux__) /* Linux allows NULL param, will return EFAULT */ - VOID_RET(int, sched_setparam(pid, NULL)); + VOID_RET(int, sched_setparam(pid, stress_get_null())); #endif /* diff --git a/stress-vm-segv.c b/stress-vm-segv.c index 44ee88282..dc23557b9 100644 --- a/stress-vm-segv.c +++ b/stress-vm-segv.c @@ -37,7 +37,7 @@ static NOINLINE void vm_unmap_child(const size_t page_size) len = len ^ (len >> 1); while (len > page_size) { - (void)munmap((void *)stress_get_uint64_zero(), len - page_size); + (void)munmap((void *)stress_get_null(), len - page_size); len >>= 1; #if !defined(__DragonFly__) shim_clflush(addr);