|
node->data = UNCONST(void *, data); |
In the following code:
node->data = UNCONST(void *, data);
Old data is replaced by the new data if the node is found in hash_table_find(). But we're not sure if ht->hash(data) is identical to ht->hash(node->data). If not, the updated node cannot be found again...
int fr_hash_table_replace(void **old, fr_hash_table_t *ht, void const *data)
{
fr_hash_entry_t *node;
node = hash_table_find(ht, ht->hash(data), data);
if (!node) {
if (old) *old = NULL;
return fr_hash_table_insert(ht, data) ? 1 : -1;
}
if (old) {
*old = node->data;
} else if (ht->free) {
ht->free(node->data);
}
node->data = UNCONST(void *, data);
return 0;
}