3 ms·
> Yet if the bar for C++ competence is "never wrote a use-after-free" The bar for C++ competence in that regard is RAII. Furthermore, your strawman doesn't ho
by geezerjay 9y ago
> Yet if the bar for C++ competence is "never wrote a use-after-free"
The bar for C++ competence in that regard is RAII.
Furthermore, your strawman doesn't hold up. The object slicing problem is actually like someone being foolish enough to cast a 64-bit int to a 32-bit int and then complaining that the programming language is broken because the 32-bit variable doesn't hold 64 bits. Of course it doesn't. Why should it? And why make excuses an play the pin-the-blame game when the problem is caused by ignorance? Heck, you're assigning heterogenous objects of variable-length to a data structure that by definition was designed to hold homogeneous sequences of fixed-size objects, and even still you want to pin the blame on the language? How, if you clearly don't know what you're doing?
- narag 9y agoIf you think about this as a correct/incorrect thing, you're going nowhere. There's this usability concept that so many people resist to apply to dev tools as if programmers were not regular humans.
- pcwalton 9y agoRAII is nowhere near enough to prevent heap use-after-free.
- vvanders 9y agoOh man, the number of libraries I've used over the years where I got nailed by their use after free/mem overwrite. Just because you're a perfect developer doesn't mean some downstream dependency isn't going to come along and wreck your day.
- hsivonen 9y ago> The bar for C++ competence in that regard is RAII. If it was that simple we'd never need kungFuDeathGrip in Gecko. Yet, we need it a lot: https://searchfox.org/mozilla-central/search?q=kungfu&path= https://searchfox.org/mozilla-central/search?q=kungfu&path= (KungFuDeathGrip is the pattern of introducing an extra RAII refcount incrementer/decrementer on the stack to avoid subsequent method calls doing something that would free an object from underneath the current stack frame.)
- pjmlp 9y agoActually no. RAII only works for stack or static global allocated resources. So if the heap allocated data isn't hidden behind some kind of smart pointer, RAII won't help. Which unless one writes 100% of the code, or there are strict code reviews in place, there isn't any guarantee that all heap allocations are guarded with RAII based handles.