jamesjuett / lobster

Interactive Program Visualization Tools
8 stars 3 forks source link

Array pointer takes on weird value when it steps off the end of the array #340

Open jamesjuett opened 2 years ago

jamesjuett commented 2 years ago

It appears that it's getting assigned the value of its index reinterpreted as a pointer, probably from a bug in the special case implementation for stepping off the end. Specifically this manifests with ++, but it may manifest elsewhere.

jamesjuett commented 2 years ago
void fill_ones(int *ptr) {
  while(*ptr) {
    *ptr = 1;
    ++ptr;
  }
}

int main() {
  int arr[5] = {3, 1, 4, 1, 5};
  fill_ones(arr);
}