adam-mcdaniel / oakc

A portable programming language with a compact intermediate representation
Apache License 2.0
725 stars 21 forks source link

Dereferenced non-allocated pointer error #75

Open adam-mcdaniel opened 4 years ago

adam-mcdaniel commented 4 years ago

To make programs more correct, runtime checks could be added for determining whether or not the program is accessing memory it does not own.

To be a valid pointer, it must either:

  1. Point to an address that is less than the stack pointer. Pointers to stack variables are valid pointers.
  2. Point to allocated memory on the heap. Non-allocated memory on the heap should not be accessed.

Dereferencing an address that violates either of those rules could throw a accessed unowned memory error.

kevinramharak commented 4 years ago

Does this mean that every dereference of a pointer has to be checked? I'm assuming performance is not really a concern right now, but does this not generate a lot of overhead?