3 ms·
> It's not simple to write memory safe code in C++, otherwise we would have a lot fewer vulnerabilities in C++ codebases. Using the STL after using Java collec
by _pmf_ 9y ago
> It's not simple to write memory safe code in C++, otherwise we would have a lot fewer vulnerabilities in C++ codebases.
Using the STL after using Java collections or Qt collections is a shock. I think there really needs to be a "Safe STL" in addition to "Performant STL" that performs range checks. You simply cannot recommend using the STL for safe code.
- signa11 9y ago> I think there really needs to be a "Safe STL" in addition to "Performant STL" that performs range checks. indeed. for gcc, you can compile stuff with '-D_GLIBCXX_DEBUG' to enable random-iterator bound checks. moreover, random-access-iterators do have the 'at(...)' stuff available for bounds checked access to the containers. but, yeah, a standardized way would be very useful.
- pjmlp 9y agoVisual C++ on debug mode also enables iterator validation and bounds checking for arrays and strings. It is also possible to explicitly enable them in release code. https://blogs.msdn.microsoft.com/vcblog/2017/06/28/security-features-in-microsoft-visual-c/ https://blogs.msdn.microsoft.com/vcblog/2017/06/28/security-...
- duneroadrunner 9y ago> I think there really needs to be a "Safe STL" in addition to "Performant STL" that performs range checks. SaferCPlusPlus[1] provides compatible, memory-safe versions of the most commonly used STL containers. (The compiler switches mentioned by others add range checking, but do not, for example, catch use-after-free bugs.) > > It's not simple to write memory safe code in C++, otherwise we would have a lot fewer vulnerabilities in C++ codebases. Using SaferCPlusPlus, it now is simple to write memory-safe code in C++. And it's not much different from writing traditional (unsafe) C++ code. [1] shameless plug: https://github.com/duneroadrunner/SaferCPlusPlus https://github.com/duneroadrunner/SaferCPlusPlus
- nicwilson 9y agoYou can't do that with C++'s "3-legged" algorithms. the begin - end - begin triplet is missing the second end.
- zvrba 9y ago> Using the STL after using Java collections or Qt collections is a shock. Why? I prefer having a free-standing generic find function as opposed to it being implemented in each and every container. Even better example: copy. You can use it with containers, but also with input/output streams (using stream iterators). You mentioned safety, is iterator invalidation bothering you?