3 ms·
That's good! That's what you want. Out-of-bounds array accesses causing segfaults is the happy case! The sad case is security vulnerabilities.
by jstanley 4y ago
That's good! That's what you want.
Out-of-bounds array accesses causing segfaults is the happy case! The sad case is security vulnerabilities.
- twic 4y agoIf dereferencing an invalid pointer reliably caused a segfault, this would be true. But it's undefined behaviour, so it can segfault, corrupt data, leak data, etc. Given that the possible behaviour is a superset of what can go wrong using an integer index, i would say it's worse. I would agree that using naive integer indices, and running the risk of accessing the wrong data, is also completely unacceptable, though.
- jstanley 4y agoI'm agreeing with you. I'm saying that a bounds checker is better than a segfault because it always works. (You're right that it actually doesn't always work because sometimes your stale index will still be inside the array but refer to a different thing, but at least it can't be abused to write into other arrays).
- alpaca128 4y agoThe alternative in Rust would be using `.get()` in those situations, which returns an optional result. That still doesn't account for valid but outdated array indices, though.