Hacker News new | ask | show | jobs
by Klonoar 699 days ago
I cannot imagine writing a method to return a value less than n, and not verifying that constraint somewhere in the safe method.
1 comments

It’s just a simple example to illustrate the point. Realistic bugs would probably involve more complex logic.

The prevalence of buffer overrun bugs in C code shows that it very definitely is possible for programmers to screw up when calculating indices. Rust removes a lot of the footguns that make that both easy to do and dangerous in C. But in unsafe Rust code, you’re still fundamentally vulnerable to any arithmetic bug in any function that you call as part of the computation of an index.