How to annoy your coworkers
Today I spent a number of hours tracking down a buffer overrun. Someone had created a set of animation data that was too large for the temporary buffer and nobody had checked for overruns.
One thing I discovered that can be done to track down trashing is the following:
class ParentClass
{
public:
int32 boundCheck;
ParentClass() : boundCheck( 0xdeadf00d ) { ; }
};
class ChildClass : public ParentClass
{
public:
ChildClass() : childBoundCheck( 0x7331f00d ) { ; }
/** ... rest of class **/
int32 childBoundCheck;
};
Which puts fenceposts at the edge of the structure you're having problems with. So if you pull up a ChildClass in your debugger and it has a
BoundCheck!=0xdeadf00d or a
childBoundCheck!=0x7331f00d you know something bad has happened to your class.
Posted by matt at March 18, 2004 05:26 PM