|
|
|
|
|
by kazinator
3037 days ago
|
|
If you write code that tests for null out of malloc, you have to commit to that code as a feature and have a test strategy for it. Simply porting the program to a platform where malloc returns null isn't enough; there are various cases to probe, like your very first malloc failing because the program was started in a low-memory environment. Or the case that the 99th malloc fails after 98 good ones. |
|
If you port to some new platform, of course you need to go back and check the docs for new error codes.
For instance, I generally abort() on NULL after printing a message.