Branching Around Code
The following example contains a logic error in which the program dereferences a null pointer:
1 int check_for_error (int *error_ptr)
2 {
3 *error_ptr = global_error;
4 global_error = 0;
5 return (global_error != 0);
6 }
The error occurs because the routine that calls this function assumes that the value of error_ptr can be 0. The check_for_error()function, however, assumes that error_ptr isn’t null, which means that line 3 can dereference a null pointer.
Correct this error by setting an evalpoint on line 3 and entering:
if (error_ptr == 0) goto 4;
If the value of error_ptr is null, line 3 isn’t executed. Note that you are not naming a label used in your program. Instead, you are naming one of the line numbers generated by TotalView.