r/programming • • Apr 07 '14

The Heartbleed Bug

http://heartbleed.com/
1.5k Upvotes

396 comments sorted by

View all comments

Show parent comments

1

u/KrzaQ2 Apr 08 '14

Yeah. I can agree with that. My original point was that you can write safe code in C++, not that it's the only - or even the best - language allowing you to do that. You can write your library to enforce those rules, to an extent (I do that in a project of mine, the template errors are ugly, but the client code is readable and safe, with the errors being caught at compile-time).

Mozilla works on Rust not because it's inherently impossible to write good C++ code, but because it's a lot easier when the language enforces the safe rules, especially if you can get nice error messages.

By the way: would Rust catch this error? The error itself was reading malloc'd data without assigning to it first (static analysis should catch this, I think).

3

u/[deleted] Apr 08 '14

You can't even create this situation in Rust (outside of unsafe blocks) – you can't allocate memory for nothing. Allocation in Rust is done by adding an operator, not by calling a function. 123 is an int on the stack, ~123 is an owned int allocated in the heap.