Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-12

Dereferencing Nil Pointers

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Emerson

I did not find "Attempted to dereference a NIL pointer" as a runtime error in FPC (except for error 204 which involves calls to dispose or Freemem).

For example:

var
  x : ^char;
  y : char;
begin
  x := nil;
  y := x^;
end.

should produce a runtime error at the second statement. This was a deficiency in Turbo Pascal. Is there any way to turn on such checking in FPC?

MarkLDE

Unknown author
to Mark Emerson
Mark Emerson wrote 13 lines
I did not find "Attempted to dereference a NIL pointer" as a runtime error in FPC (except for error 204 which involves calls to dispose or Freemem). For example: var x : ^char; y : char; begin x := nil; y := x^; end.

This is the error I get:

Runtime error 216 at 0x080548BD
0x080548BD
0xBFFFF33C
0x080480B0

Michael.

Jonas Maebe
to Mark Emerson: I did not find "Attempted to dereference a NIL pointer" as a runtime error in FPC (except…
Mark Emerson wrote 16 lines
I did not find "Attempted to dereference a NIL pointer" as a runtime error in FPC (except for error 204 which involves calls to dispose or Freemem). For example: var x : ^char; y : char; begin x := nil; y := x^; end. should produce a runtime error at the second statement. This was a deficiency in Turbo Pascal.

Actually, it's a deficiency in 16 bit Dos, which can't do zero page protection. It's still a problem under Windows when running 32 bit Dos programs, because for some strange reason Windows doesn't allow DPMI programs to turn on zero page protection (running this program under Dos/go32v2 does produce a segmentation fault). In all other cases, this will cause a segmentation fault (run time error 216).

Jonas