The FUZZ_malloc_rand() function was incorrectly always returning NULL for
zero-size allocations. The random offset generated by
FUZZ_dataProducer_int32Range() was not being added to the pointer variable,
causing the function to always return (void *)0.
return mem;
} else {
uintptr_t ptr = 0;
- /* Add +- 1M 50% of the time */
+ /* Return junk pointer 50% of the time */
if (FUZZ_dataProducer_uint32Range(producer, 0, 1))
- FUZZ_dataProducer_int32Range(producer, -1000000, 1000000);
+ ptr += FUZZ_dataProducer_int32Range(producer, -1000000, 1000000);
return (void*)ptr;
}
-
}
int FUZZ_memcmp(void const* lhs, void const* rhs, size_t size)
/**
* malloc except returns random pointer for zero sized data and FUZZ_ASSERT
* that malloc doesn't fail.
+ * WARNING: Only free the returned pointer if size > 0!
*/
void* FUZZ_malloc_rand(size_t size, FUZZ_dataProducer_t *producer);