This seems to assume that the new hashtable key gets inserted into the first element of the bucket list at that hash-value, which isn't necessarily true. What if something else already hashed to that earlier and is already occupying the first element of the bucket list ?  This is why the "htab_add" routine has a "while(node->next)  node = node->next;" loop which makes it to the last element of the bucket list.