Earlier quoted context omitted.
Not quite for memory _corruption_ but back when I was writing API code in C, I would place 'sentinels' at each end of my structs. struct somestruct { int s1; int data; char * moreData; int s2; } When the caller of the API needed to call my code, it had to first call a function to get an instance of the struct. This constructor like code would allocate the memory for the struct, and then set s1 and s2 to 0xDEADBEEF; T…
This one is compelling. However this might not have caught the error condition described upthread. That condition might have overwritten data or moreData without touching s1 or s2 . Otherwise, great!
Also to all those ready to do a checksum on a struct, rememember that structs are plattform dependant (padding bytes).