4 ms·
I urge anybody using a C family language to become familiar with AddressSanitizer [1], a tool that (with support from the compiler) detects an impressive variet
by pjscott 4y ago
I urge anybody using a C family language to become familiar with AddressSanitizer [1], a tool that (with support from the compiler) detects an impressive variety of memory bugs at runtime. The scenario you describe would result in the program immediately crashing with a read-after-free error, along with stack traces for the most recent calls to malloc and free that involved that address. It's remarkably useful and straightforward, and Apple's tooling has good support for it, along with Xcode integration [2].
[1] https://clang.llvm.org/docs/AddressSanitizer.html https://clang.llvm.org/docs/AddressSanitizer.html
[2] https://developer.apple.com/documentation/xcode/diagnosing-memory-thread-and-crash-issues-early https://developer.apple.com/documentation/xcode/diagnosing-m...
- dlundqvist 4y agoThis. I personally think ASAN and it's friends are some of, if not the, best things to happen to C/C++ in the last decade. We use it at work, I use it in all my personal projects. We've found "countless" bugs with ASAN together with LSAN. It should be part any project from the start, run as much as possible with ASAN when the performance hit can be afforded.
- pseudoramble 4y agoJust confirming, but you're taking about Leak Sanitizer? https://clang.llvm.org/docs/LeakSanitizer.html https://clang.llvm.org/docs/LeakSanitizer.html. Not really familiar with these tools, definitely not the acronyms.
- dlundqvist 4y agoSorry, yes, I meant Leak Sanitizer.
- pseudoramble 4y agoNo need to be sorry! I appreciate it! It was actually in the link the parent posted. I just missed it at first.
- thewebcount 4y agoAgreed! Likewise, if you're doing anything multithreaded, ThreadSanitizer (TSAN) is a must!
- rock_artist 4y agoI’m using sanitizers on macOS for few years now. Doing cross-platform, ~~it really feels inferior~~ I really miss them on MSVC side. (wrt to exclusive asan since VS2019) Still, in some cases you have some tiny uninitialized member for example that is much harder to find. So with this malloc it might even cover those more.