![]() |
Home |
|
Catching NULL Pointer AssignmentsThe nastiest type of bug results from the use of uninitialized or corrupted pointers. The most frequent incorrect value of a pointer is NULL (0). The simplest method to catch these errors is to make the first page of memory inaccessible. Of course, paging must be used to achieve this. The simplest method is to define a region of 4k size at address 0 and give it NoAccess access rights. Example:Region FirstPage 0 4k RAM NoAccess Region LowMem 4k 636k RAM Assign ... This will guarantee that all references to address 0 will trigger an exception at run-time. If you want to avoid wasting a whole page of memory, you could just remap it: Region FirstPage 0 4k RAM Assign Region LowMem 4k 636k RAM Assign Region HighMem 1M 3M RAM Assign FillRAM HighMem ... If you don't allocate anything to region FirstPage, RTLoc will append the physical memory page at address 0 to the end of HighMem, making it available for the heap and stack. However, you should consider that this approach will destroy the real mode interrupt vector table and the real mode BIOS data area. This is usually no problem, but if your program needs to look up some information in this area at run time, you can't use this approach. Instead, region FirstPage would need ReadOnly or ReadWrite access.
|