Merge pull request #4403 from dloidolt/fix_FUZZ_malloc_rand

fuzz: Fix FUZZ_malloc_rand() to return non-NULL for zero-size allocations
This commit is contained in:
Yann Collet
2025-06-09 10:57:59 -07:00
committed by GitHub
2 changed files with 3 additions and 3 deletions
+2 -3
View File
@@ -31,12 +31,11 @@ void* FUZZ_malloc_rand(size_t size, FUZZ_dataProducer_t *producer)
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)
+1
View File
@@ -66,6 +66,7 @@ void* FUZZ_malloc(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);