5 ms·
The bug that is detailed in the article. Wouldn't have happened with Rust.
by IshKebab 4mo ago
The bug that is detailed in the article. Wouldn't have happened with Rust.
- senfiaj 4mo agoThere was also a bug in the Linux kernel, or did I miss something?
- IshKebab 4mo agoYes there was. It's detailed in the article.
- senfiaj 4mo agoBut why wouldn't have happened with Rust? Sorry I can't find anything about Rust in the article. Or you mean if the Linux kernel was written in Rust and that stupid bool coercion was not possible?
- grg0 4mo agoIt's the latter; Rust won't allow the int->bool coercion. Though to be absolutely pedantic, !x is an int for x:int in C, there is no bool coercion involved; an if-statement takes an expression of any scalar value and evals to true on non-zero. Not that that helps to avoid introducing bugs anyway.
- IshKebab 4mo agoBecause Rust programmers would have used an enum or Result.
- grg0 4mo agoThis is not a memory safety bug, but a bug resulting from a type coercion of int to bool. I don't know if Rust is stricter but your original statement was confusing.
- IshKebab 4mo agoExactly my point. Lots of people think Rust only prevents memory safety bugs, but this is an example of a bug that isn't a memory safety bug but also wouldn't have happened in Rust. They used an int with special meanings for negative/0/positive values. Very common in C, and not at all type safe (all meanings have the same type). In Rust you would use an enum or Result, it would be type safe and the refactoring mistake they made would have been a compile time error.