Hacker News

Favorites Setup
Comment by delifue | original | C for Rust programmers
[−]delifue · 2026-10-11 Sun 02:50 UTC · link
There is a nuanced mistake in

> If your machine runs out of memory, reversed[i] will cause a segfault upon being accessed. In order to avoid unhelpful segfaults, the program should check for a null pointer and gracefully exit if one is found

If overcommit is enabled (often by default), malloc will not return null when machine runs out of memory. malloc will still return null if input argument is invalid (e.g. too large).

[−]tgv · 2026-10-11 Sun 08:14 UTC · link
Isn't that more of an environmental factor than a language feature? I would expect Rust applications to suffer the same way.
[−]delifue · 2026-10-11 Sun 11:18 UTC · link
Yes, same applies to Rust
[−]pornel · 2026-10-11 Sun 10:23 UTC · link
It's a mistake to assume that Linux with overcommit is the only platform that C runs on.
[−]delifue · 2026-10-11 Sun 11:21 UTC · link
Overcommit is very common now, including desktop, mobile and server, even in contianers. Checking malloc returning null only prevents OOM in places like embedded.