3 ms·
There's some good advice in chapter 8 of Code Complete on Defensive programming. One example given there is the C function realloc, which resizes a block of mem
by Robin_Message 16y ago
There's some good advice in chapter 8 of Code Complete on Defensive programming. One example given there is the C function realloc, which resizes a block of memory, which can sometimes mean moving the whole block to a new, larger block. Since intermittent bugs are indeed the worst kind, Steve suggests making the debug compile memory allocator always move the block, so as to exercise that code path everywhere in testing.
Edit: Wrong Steve and wrong book -- it's a running example in "Writing Solid Code" by Steve Maguire.
- jacquesm 16y agoThat's a good trick, regardless of which book it came from. In the software I wrote about above I suspect a very subtle resource leak. A nice example of such a leak is for instance forgetting to close an opened file descriptor if some other rare error condition occurs elsewhere in the code (not that that's it, but that's how you can get to the point where something will run for months on end without crashing and then suddenly it does). File descriptor leaks can be relatively easily traced using lsof by the way (one of the step-child utilities that really should be in every coders toolbox, right next to gprof and make).
- xsmasher 16y agoGood tip; I believe Guard Malloc does this for you.