Re:Show HN: Progressbar - A C library for displaying command...
by sovande on Saturday August 29, 2015 @04:28AM
(#10139438)
On virtual memory systems, it is a safe bet that malloc will "never" fail to return a value. It is just good form to check the return value of system calls. If you program for embedded systems (e.g. Arduino) and bring over the bad habit of never checking malloc, you are going to be in for a surprise. I'm not sure, but I believe on iOS, malloc could fail on the device.
Re:Show HN: Progressbar - A C library for displaying command...
by dalke on Saturday August 29, 2015 @04:27AM
(#10139437)
That link shows that malloc failed, just not due to exceeding available RAM. At the end it says "malloc finally failed because of address space exhaustion."
Re:Show HN: Progressbar - A C library for displaying command...
by danieltillett on Saturday August 29, 2015 @05:01AM
(#10139475)
If the memory was actually being used it would have crashed long before that. The test was kind of artificial.
Re:Show HN: Progressbar - A C library for displaying command...
by dalke on Saturday August 29, 2015 @05:38AM
(#10139515)
Absolutely. I was pointing out that "It is impossible for malloc to fail" is, according to the linked page, an incorrect summary.
Re:Show HN: Progressbar - A C library for displaying command...
by danieltillett on Saturday August 29, 2015 @06:55AM
(#10139623)
It is still pointless checking if malloc fails on linux :)
Actually the real issue here is that you should be aware that on some systems malloc might fail and not segfault.
Edit. It is impossible for malloc to fail (at least on linux) [1]. Seems rather pointless checking for something that can’t happen.
1. https://scvalex.net/posts/6/