munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.43k stars 1.01k forks source link

Code issue in tableGet #1069

Open chrisjbreisch opened 1 year ago

chrisjbreisch commented 1 year ago

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.