4 ms·
`malloc` won't fail, right?
by benburleson 7y ago
`malloc` won't fail, right?
- spookthesunset 7y agothe javascript will enforce the user input. no need to have the backend check it again!
- hnarn 7y agoThis should be a joke, but considering how often it's actually the case it's unfortunately not that funny.
- cryptonector 7y agoIt won't on Linux! But hey, random processes will get OOM-killed.
- zenhack 7y agoYou can turn off overcommit, in which case you'll get a null return instead of OOM killing. But also, you can still get a malloc failure without actually be running out of memory if the allocator can't find a big enough contiguous chunk of address space. This is highly unlikely on a 64 bit system, but if you try to malloc gigabytes on a 32 bit machine you might see it.
- Iv 7y agoAnd also, you never know when this theoretical case actually happens but it did happen to me: at one point someone may use your code on an Arduino and unexpectedly, it works! But memory allocation could fail more than you expect!
- NullPrefix 7y agoOn Unix it won't. You can overcommit memory and only get into trouble when you actually try to page it. But not at malloc time.
- patrickthebold 7y agoIirc that's configurable.
- ci5er 7y agoNot as much as developers who can't find their own coding errors might have you think!