In this section:
This problem occurs when an attempt is made to dereference a pointer whose value is invalid or that Insure++ did not see allocated. There are several causes of this problem:
This section focuses on the first type of problem described here. For information about the second type of problem, contact Parasoft’s Quality Consultants.
|
The following code attempts to use the address of a variable but contains an error at line 8 - the address operator (&
) has been omitted.
/* * File: writwld1.c */ main() { int i = 123, *a; a = i; *a = 99; return (0); } |
[writwld1.c:9] **WRITE_WILD** >> *a = 99; Writing to a wild pointer: a Pointer : 0x0000007b Stack trace where the error occurred: main() writwld1.c, 9 |
Most compilers will generate warning messages for this error because the assignment in line 8 uses incompatible types.
Another version of the same problem can occur when using union
types. The following code first assigns the pointer element of a union but then overwrites it with another element before using it.
/* * File: writwld2.c */ union { int *ptr; int ival; } u; main() { int i = 123; u.ptr = &i; u.ival = i; *u.ptr = 99; return (0); } |
This code will not generate compile time errors.
[writwld2.c:15] **WRITE_WILD** >> *u.ptr = 99; Writing to a wild pointer: u.ptr Pointer : 0x0000007b Stack trace where the error occurred: main() writwld2.c, 15 |
The simpler types of problems are most conveniently tracked in a debugger by stopping the program at the indicated source line. You should then examine the illegal value and attempt to see where it was generated. Alternatively, you can stop the program at some point shortly before the error and singlestep through the code leading up to the problem. Note that wild pointers can also be generated when Insure++ has only partial information about your program’s structure. For more information about this topic, contact Parasoft’s Quality Consultants.