Null Pointer Assignment
ID: Q71252
|
The information in this article applies to:
-
Microsoft CodeView for MS-DOS, versions 2.2, 3.0, 3.11, 3.14, 4.0, 4.01, 4.05, 4.1
-
Microsoft CodeView for OS/2, versions 2.2, 3.0, 3.11, 3.12, 3.5
SYMPTOMS
RESOLUTION
STATUS
MORE INFORMATION
The location of the null segment can be observed in a link map. It
starts at DS:0 and is 42H bytes long. The Microsoft copyright notice
is written there at program startup and if this area is written to
during the course of the program, the run-time error R6001 will be
generated upon program termination.
The most common cause of this error is using a pointer that has not
been initialized to point to a memory area. Pointers that have not had
space allocated for them [for example, with malloc()] or that have not
been assigned to point to a specific data element (for example, arrays
or structures) are considered uninitialized. Writing to one of these
pointers generally results in an overwrite of the null data segment.
With CodeView versions 1.0, 2.0, 2.1, 2.2, 2.3, and 2.35, the
procedure described above should be used for locating the source of an
R6001 error. With CodeView versions 3.0 and above, you may also use
the following menu and keyboard commands to set the breakpoint for
tracking down a null pointer assignment:
- Press the F8 or F10 key to step into main().
- Select Set Breakpoint from the Watch menu.
- Choose "Break When Expression Has Changed" from the Set Breakpoint
dialog box.
- In the Expression field, enter DS:0.
- In the Length field, enter 0n66.
- Choose OK, or press ENTER.
- Press the F5 key to run the program.
As described above, the program will then break immediately after the
errant pointer has written to the null segment.
Note that it may be necessary to clear any breakpoints on the null
data segment and restart the program before entering the above
commands in order for these procedures to work correctly.
In addition, any breakpoint on DS:0 may stop execution if DS changes.
For example, if the above breakpoint is set and the program is
restarted under CodeView, the program will break during the C start-up
code [before reaching the main() function], since the C start-up sets
DS to the default data segment. [This is also the reason you must step
into main() before setting the breakpoint in the first place,
otherwise you would not be setting the breakpoint on the correct
segment.
Additional query words:
kbinf 3.00 4.00 4.10
Keywords : kb16bitonly
Version : :2.2,3.0,3.11,3.12,3.14,3.5,4.0,4.01,4.05,4.1
Platform :
Issue type : kbprb
|