4 ms·
> Look at all the points where memory is allocated, and then make sure it is freed, exactly one time, no more, no less. C is clearly the wrong language for som
by IshKebab 12y ago
> Look at all the points where memory is allocated, and then make sure it is freed, exactly one time, no more, no less.
C is clearly the wrong language for something this security critical if that's where your bugs are. C++ solved this many years ago.
- AceJohnny2 12y agoWhile I agree that C is the wrong language for security-critical applications (and I write this as a mostly C developer myself), I strongly disagree that C++ is a better language. Sure, it has constructors and destructors and pass-by-reference, but that's not enough, and cons/destr's don't fit the common memory usage-model of performance-critical applications (where an SSL library is often used), which use preallocated memory pools.
- wtetzner 12y agoSeems like an area where Rust could really shine.
- programminggeek 12y agoGood pun.
- tormeh 12y agoHow about Ada?
- krylon 12y agoI think - please correct me if I'm wrong - that Ada has pretty much the same problems as C if you use manual dynamic memory management. Ada supports Garbage Collection in theory, but it is optional, and I don't think many implementations actually supply a GC. Especially since Ada apparently is often used in realtime systems where dynamic memory management is usually avoided altogether (there is a subset of Ada specifically designed for building realtime software that explicitly prohibits any dynamic memory management). Ada is - as far as I remember - much safer with regards to buffer overflows and bounds checking. But the bigger problem is probably that far more developers know C than Ada, and that something like an SSL library intended for widespread use needs to work with many different compilers and linkers. If you use GCC, I think it is possible to compile Ada code using the GNU Ada compiler and link it to C code compiled using the GNU C compiler, but I am not sure how things look if you use some other C compiler.
- masklinn 12y agoIt'll probably be better once the placement box becomes pluggable (so that it's possible to use specific allocators piecemeal)
- tpush 12y agoWell, good then that C++ allows you to easily use your own memory allocation scheme via custom allocators. You can even use STL's data structures :-).
- smosher_ 12y agoYou had me up to "C++."
- GFK_of_xmaspast 12y agoI fixed a double-delete bug just this month in some c++ code.
- IshKebab 12y agoSo? I didn't say no C++ code has bugs. I said C++ is a better language for eliminating memory errors. Obviously this only happens if you take advantage of the features that allow that (RAII, smart pointers, etc).