I'm trying to replicate the strdup
function in C. It's part of an exercise for school. I'd like to unit test it, including the case where malloc
returns NULL
and sets errno
to ENOMEM
.
I'm on OSX 10.8.
I've tried limiting the stacksize, then datasize, realizing malloc allocates on the heap:
limit stacksize 0
limit datasize 0
Confirmation that limiting should have worked:
my-host% limit
cputime unlimited
filesize unlimited
datasize 0kB
stacksize 0kB
coredumpsize 0kB
addressspace unlimited
memorylocked unlimited
maxproc 709
descriptors 256
However, even with a limit of 0kB for the stack size, I am able to run programs just fine. So I'm thinking there might be a restriction on my host on the minimum stack size.
How else could I test the case where malloc
returns NULL
?