logoalt Hacker News

Chai-T-Rex • today at 6:49 AM • 2 replies • view on HN

That's not really a memory safety bug, due to the fact that it panics rather than doing something unsafe.

The `variable[i]` notation is intended to function like in other languages, where it returns an unwrapped value. It would be ugly, noisy, unergonomic, and annoying to have to properly handle `Some` (like in `variable[i].unwrap()`) every single time you ever used it. Imagine doing `c[i].unwrap()[j].unwrap() += a[i].unwrap()[k].unwrap() * b[k].unwrap()[j].unwrap();`.

If you really want the result to be wrapped in `Some`, you can use `variable.get(i)`.


Replies

cube00 • today at 7:12 AM

> That's not really a memory safety bug, due to the fact that it panics rather than doing something unsafe.

The ? operator can be nicer to read then all those .unwraps() as an alternative and doesn't panic.

I guess the concern with panics is you're not forced to think about how you want to handle them like you do when you get a `Result` or `Option` returned.

As a result it could be used as a DDOS against your app if it's network accessible.

➕ show 2 replies
rendaw • today at 7:47 AM

GP didn't say it was a memory safety bug.