4 ms·
>For example, how often have you seen a malloc check for `ENOMEM`? I've never concerned myself with that, but it's apparently a lot more complicated than just
by perl4ever 6y ago
>For example, how often have you seen a malloc check for `ENOMEM`?
I've never concerned myself with that, but it's apparently a lot more complicated than just doing that check.
See:
https://news.ycombinator.com/item?id=20143277 https://news.ycombinator.com/item?id=20143277
https://scvalex.net/posts/6/ https://scvalex.net/posts/6/
Some of the thread is hilarious, for instance:
"malloc is not allowed to return a non-null pointer to a memory block that cannot be written to. Linux does it anyway, and in doing so blatantly violates the standard.
...
That is my point, it doesn't fail. Either the kernel finds out a way to map the memory and it succeeds, or it kill the program and the instruction never runs. Code that doesn't run can't violate the standard."