Did they say that?
Did they say that?
Which, by the way, do not apply, since the SHA256-Code is marked unsafe.
Contrast that with C, where every line may be a source of safety issues. It's a meaningful difference.
There is another issue: Unsafe code in Rust could violate assumptions that could cause other code in Rust to be unsafe. So it needs more care to write than regular C.
But I agree that it still a huge net benefit with respect to memory safety, but let's not exaggerate.
So I agree with the point in principle, I just do not like the "spin" of "every line of C is time bomb nobody can understand" while in Rust you just have to look at some lines of "unsafe" and all is good.
unsigned int mul(unsigned int x, unsigned int y) { return x * y; }
Or there are many high level function structures as, which also has no UB (with some assumption on the called functions):
void bar() { struct foo *p = foo_alloc(); foo_do1(p); foo_do2(p); foo_delete(p); }
Such code can be easily screened and also this can be done automatically. There is a lack of open-source which can do this, but I have an experimental GCC branch which starts to do this and looks promising.
unsigned short mul(unsigned short x, unsigned short y) { return x * y; }
I don't know about you, but I wouldn't think to treat these any differently unless I put on my language lawyer hat.
But I also do not worry about signed overflow anyhow, because compilers can turn them into traps.
Language standards shouldn't rely on compiler options to save developers here. There's a lot of compilers in the world that don't support the same range of options GCC and clang have, like CompCert. Those are often the ones building safety-critical applications these days, where trapping would be inappropriate.
Whether trapping is appropriate or not depends on the context, but it surprising to hear as an argument, because Rust also has a fail hard policy...
void bar() { struct foo *p = foo_alloc(); foo_do1(p); foo_do2(p); foo_delete(p); }
Are we assuming foo_alloc always succeeds? malloc returns NULL to indicate failure to allocate, which this code wouldn't handle.> Such code can be easily screened and also this can be done automatically.
That doesn't sound right at all. Robust static analysis of C code is extremely involved. It's an area of ongoing research.
Prior efforts along these lines have not been successful. Even adopting the MISRA C ruleset doesn't guarantee absence of undefined behaviour, for instance.
Any "unsafe" block within a rust source code potentially corrupts the entire application as undefined behavior has no bound and will/may leak right out of the unsafe block.
You are arguing something else. Enumerating all unsafe code is a good feature, but when one of the fundamental building blocks of your security is marked unsafe, it raises questions about its overall benefit.
I'm emphasizing the difference between rust and C here because unlike Martin, I don't agree that it's meaningfully possible to eliminate UB in C by careful analysis. You're able to do this in Rust in large part because those issues are all concentrated in a few tightly scoped blocks with clear responsibilities.
Unsafe also gives you a massive hint where to look when you're debugging.