craftinginterpreters icon indicating copy to clipboard operation
craftinginterpreters copied to clipboard

Code issue in tableGet

Open chrisjbreisch opened this issue 3 years ago • 0 comments

It's not quite a bug but could be better. This section of code:

  if (entry->key == NULL) return false;

  *value = entry->value;
  return true;

I think a better implementation would be:

  *value = entry->value;
  return entry->key != NULL;

Yes, I can always check the return value from tableGet, but setting *value regardless of the return value is safer. User will get a NIL_VAL back if the entry isn't found, rather than what they sent in.

chrisjbreisch avatar Jul 13 '22 02:07 chrisjbreisch