Hi,
I currently trying to do unit testing on some function using the Unity library, and in some of the functions I'm checking the return of malloc to ensure it doesn't return NULL for example.
But I was wondering how can I try to fail the malloc function without changing the arguments ? Is there a way to cap the memory allocation so it cannot allocate more for example ?
And if it exist do you have a way to do "enable" it for 1 unit test then "disable" it when the test is done ?
I know that usually malloc is safe, and I could "not care about if it has an error" but still just to make sure I want to try testing it
[link] [comments]






![The Gang Republic: Inside Haiti’s New Order (2026) - ~3 million people living in the grips of all-out gang war. France24 spent a fortnight filming in and around the Haitian capital, speaking to a population held hostage by this drawn-out crisis (CC) [00:52:38]](https://external-preview.redd.it/0j1B98qWy2MAsjLEwjT10EbknBToMVuWRJ-tUeZsTso.jpeg?width=320&crop=smart&auto=webp&s=041d55dee546ef807e7eda2e0d1d013111f02a25)

English (US) ·