I am writing unit tests for a library I am developing. The library implementation cannot be mocked. The unit test is about returning a special value when the program runs out of memory.
I came up with this naive solution:
// Fillup memory
int *p = NULL
do {
p = malloc(sizeof(int));
// store p somewhere to release it later
} while(p);
// Got out of memory :)
Is there anyway to fill up the memory faster than this solution without increasing the memory block size allocated with malloc ?
PS: Using a third party memory allocator is forbidden :)