-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple idea (and question) #10
Comments
C
Note that STL containers provide two ways for subscripting (independent from C assertions):
Also C++ provides compile time assertions via So we really have a lot of options, we just need to stick to good ones. |
Ok. I actually know that, mikucionisaau. I think what the community needs to decide is:
Thanks for the attention. |
Yes, the answer is yes :-) but what specifically would you like to see? There are many options for sanitizers, see Undefined Behavior Sanitizer, Address Sanitizer, Leak Sanitizer, Thread Sanitizer: Also Stack Smashing Protector: https://wiki.osdev.org/Stack_Smashing_Protector Very useful. Most are available as built-in options in GCC, Clang and some are in MSVC. I just do not like the idea of duplication: I follow the DRY principle, otherwise maintenance is a hell. |
Recently I've watch a CppNow video about Attachable Leak Sanitizer from Bojun Seo that seems cool too because it doesn't make the code slow like Valgrind does. |
I was thinking about memory safety recently but I'm still learning C++ and I'm not an advanced user but based on all the lectures I've watched I had this simple idea but I'm not sure how useful it could be.
The programming languages provide memory safety usually by not allowing memory errors to occur(like GC or Borrow checker) but C++ currently works with a mix of strategies, like smart pointer and static analyzers etc.
It seems to me that avoiding memory errors is not really necessary if the language could just spot and notify the user of all memory errors and and related problems. Completely avoiding memory error have the cost either making programming harder or in runtime performance.
One strategy that could help is to have double versions of memory unsafe libraries and features. One version would be just to debug the code, where more verifications related to memory safety could be performed and other version would be the production one, to be used after all related memory issues were fixed.
This way we could put much more code to check for memory safety inside librarys like bounds checking in all index operations, std::shared_pointer could perform more checks like cyclic reference, etc. In debug mode even the c++ runtime could perform some checks. That would impact the program performance but just in the debug mode.
After all issues were fix it would be just a matter of use some -DNDEBUG flag and recompile the code and we would have a correct and performant version running.
Adding just bounds checking to everything would not be a complicated process because the duplicated library would not be so much different from the current ones in the standard and thus not hard to maintain.
If the code could detect all memory errors it could be just a matter to use some fuzzing to the program inputs and all errors could be found.
I wrote this simple Array example in two versions just to illustrate the idea. Do you think this approach could be useful?
The text was updated successfully, but these errors were encountered: