Shnatsel / libdiffuzz

Custom memory allocator that helps discover reads from uninitialized memory
Apache License 2.0
163 stars 8 forks source link

Return null pointer in case allocation fails. #5

Closed Shnatsel closed 6 years ago

Shnatsel commented 6 years ago

This is the behavior that POSIX prescribes and libdiffuzz-c99 already implements

Thanks to InaneB0b on Reddit for pointing this out

Shnatsel commented 6 years ago

@PlasmaPower GitHub won't let me add you as a reviewer, but I'd appreciate if you could take a look.

PlasmaPower commented 6 years ago

To get a null pointer, use ptr::null_mut(). Instead of putting the rest of the code in an else statement, I'd use an early return.

Shnatsel commented 6 years ago

Thanks! ptr::null_mut() is much better.

I rather like the else statement to make it obvious that the function returns something either way. That might be baggage from dynamically typed languages, IDK.