Hacker News new | ask | show | jobs
by MobiusHorizons 201 days ago
Wow, that’s crazy. Does anyone have any context on why they didn’t fix this by either disallowing NULL, or not treating the pointer as non-nullable? I’m assuming there is code that was expecting this not to error, but the combination really seems like a bug not just a sharp edge.
2 comments

Treating the pointer as not-nullable is precisely the point of the feature, though. By letting the compiler know that there's at least N elements there, it can do things like e.g. move that read around and even prefetch if that makes the most sense.
Indeed, at a minimum you should be able to enforce that check using a compiler flag.
You can add that check using -fsanitize=null (and you may want to turn the diagnostic into a run-time trap)