4 ms·
It's probably not quite equivalent but I believe Frederico & al found & fixed a number of issues when they converted librsvg to rust. You may want to check the
by masklinn 8y ago
It's probably not quite equivalent but I believe Frederico & al found & fixed a number of issues when they converted librsvg to rust. You may want to check the archives on their blogs (IIRC it's split between Frederico's own and the librsvg one) for more, or specifics.
But "safe" rust at least intrinsically protects from use-after-free, double free, dangling pointers, null-pointer dereferences, out-of-bounds accesses, … You may still have logic bugs of course (though the richer type system expressivity also allows better static encoding of application & domain logic), but these baseline memory-safety issues will only be a problem in specific and tagged `unsafe` blocks rather than throughout the application.
- kevincox 8y agoWhile I do believe that rust will prevent many memory safety issues. I think you would probably catch a bunch of safety issues rewriting any code.
- ryanmarsh 8y agoI think you would probably catch a bunch of safety issues rewriting any code. As well as introduce new ones.
- kevincox 8y agoOf course. I would suspect that with Rust you would introduce less new ones but I just wanted to point out that finding bugs isn't evidence that the language helped you out. Even though I am a believer I would love to see some solid evidence of Rust making code safer.
- derefr 8y agoThat's only if you rewrite "from the design" in a fresh repo. If, on the other hand, you rewrite the code line by line from C to Rust (which Rust is actually quite amenable to!), faithfully translating the semantics of the C code into the Rust code (and thereby having to use lots of unsafe{} blocks) then you can avoid most of the problems—what you'll end up with will essentially be the same as what a hypothetical C-to-Rust transpiler would output. Importantly, you can also translate the test suite in this same way. After that step is done, you can just refactor the resulting code, replacing unsafe{} blocks with Rust idioms, and then rerunning the tests (which you can leave un-idiomatized) as regression tests.
- brian-armstrong 8y agoAll of the pointer issues you mentioned have already been solved in C++ by unique_ptr.
- pjmlp 8y agoGood, now try to enforce developers to actually use it on their code and all third party libraries they link to. Ah, and not passing it around by address or reference, instead of actually moving ownership. C++17 is a great improvement, but for it to work out in this context, developers need to actually write C++ instead of "C with C++ compiler".
- brian-armstrong 8y agoThis is a silly argument. When evaluating whether to use a tool, you should consider how /you/ would use the tool, not how someone else does.
- dbaupp 8y agoPretty much only use-after-free and double-free of that list is truly solved by unique_ptr, which is great, but nothing like what you say: - std::move out of a unique_ptr x and "*x" is a null pointer dereference, - take a reference into a unique_ptr, and it becomes dangling if it is held after the pointer is deallocated, - an T[N] array doesn't get bounds-checked whether or not it is stored in a std::unique_ptr (it is nice that it reduces the number of raw pointers flying around, which likely does reduce the number of out-of-bounds accesses, but it doesn't solve them)