News for hackers. Stuff that matters.
Re:Why you should, actually, rewrite some of it in Rust by blub on Wednesday July 12, 2017 @01:26PM (#14754475)
I struggle to imagine how you could be more wrong. C offers minimal if any possibilities for writing safe code, while C++ offers many.

Anybody who has the faintest clue about both languages should know that.

Re:Why you should, actually, rewrite some of it in Rust by pcwalton on Wednesday July 12, 2017 @02:36PM (#14755243)
I actually feel that C++ memory management is less safe than that of C, because smart pointers provide the same opportunity for use-after-free while being much more opaque about when the destruction occurs. The rules about when destructors of temporaries are called in the evaluation of expressions are subtle.
Re:Why you should, actually, rewrite some of it in Rust by blub on Wednesday July 12, 2017 @04:06PM (#14756157)
I'd be happy to discuss an example, because right now the idea that smart pointers are opaque about destruction is unfortunately too abstract for me to give a helpful reply to.
Re:Why you should, actually, rewrite some of it in Rust by pcwalton on Wednesday July 12, 2017 @04:58PM (#14756622)
Consider situations like this: https://stackoverflow.com/questions/17362673/temporary-lifet...

It's undefined behavior, despite not calling free anywhere. Replace with std::string and it could be use after free. In C, UAF wouldn't happen that silently for heap memory.

Re:Why you should, actually, rewrite some of it in Rust by blub on Thursday July 13, 2017 @03:31AM (#14759413)
A similar example was posted by matthieu_m on Reddit a while back, but that's still not worse than C, even if it's an unfortunate gap in compiler diagnostics.

From my POV compilers should warn that this code is potentially dangerous. My rule is: never return a reference or pointer from a function to something whose lifetime you don't have control of.

Re:Why you should, actually, rewrite some of it in Rust by pcwalton on Thursday July 13, 2017 @05:03AM (#14759802)
It's worse than C because you can't have UAF in C without explicitly calling free (or a function that transitively calls free). In C++ freeing is implicit.
Re:Why you should, actually, rewrite some of it in Rust by nine_k on Wednesday July 12, 2017 @04:39PM (#14756445)
Do you even explicitly free() a RAII-managed pointer? If yes, why?
Re:Why you should, actually, rewrite some of it in Rust by pcwalton on Wednesday July 12, 2017 @04:59PM (#14756627)
No, and that's the problem. Free can effectively be called invisibly, causing UAF.
Re:Why you should, actually, rewrite some of it in Rust by akavel on Wednesday July 12, 2017 @07:33PM (#14757585)
C is kinda small enough, that I imagine one can maybe have some chance at trying to hold the whole of it, including all nuances/warts, in one's head. Like, maybe even actually write a compiler for it. (See e.g. Dennis Ritchie, Fabrice Bellard.)

With C++, good luck even reading and understanding The ISO C++ Standard. Not to say fully internalizing all possible interactions between all nuances. I presume not all of them may even be truly 100% fully fleshed out and explored in The Book. As to writing a compiler - even just writing a parser for C++ is famously super hard!

Re:Why you should, actually, rewrite some of it in Rust by pjmlp on Thursday July 13, 2017 @03:10AM (#14759330)
> C is kinda small enough, that I imagine one can maybe have some chance at trying to hold the whole of it, including all nuances/warts, in one's head.

Anyone that is able to keep in mind the documented 200 cases of UB is my hero.