Wednesday, April 18, 2007

Sawdust and magic numbers

Ah, the sweet smell of sawdust (and the annoying high-pitch whine of a mitre saw).... Floor being installed, finally.

Working from home. Continuing to debug my win32 heap corruption problem. Learned that the debug version of Microsoft's heap manager does do some memory poisoning under various condition to help assist in debugging corruption (think 0xDEADBEEF but for Win32)

Once again, Wikipedia to the rescue. Turns up the magic numbers are documented:

http://en.wikipedia.org/wiki/Magic_number_%28programming%29

TO summarize, here are the relevant constants for Win32:

0xABABABAB LocalAlloc() guard bytes
0xBAADF00D LocalAlloc() uninitialized allocated heap memory
0xCCCCCCCC Uninitialized stack memory (C++ runtime)
0xCDCDCDCD Uninitialized heap memory (C++ runtime)
0xFDFDFDFD C++ allocator guard bytes
0xFEEEFEEE HeapFree() poison

The next time you see a debug program crash, look for one of these constants and there's a good chance you can immediately tell the class of memory corruption.