/* key - return the key of the (key, value) pair at the current position */
void *
-hashtable_iterator_key(struct hashtable_itr *i)
+hashtable_iterator_key(struct hashtable_itr *itr)
{
- return i->e->k;
+ if (itr == NULL || itr->e == NULL)
+ return NULL;
+
+ return itr->e->k;
}
/*****************************************************************************/
/* value - return the value of the (key, value) pair at the current position */
void *
-hashtable_iterator_value(struct hashtable_itr *i)
+hashtable_iterator_value(struct hashtable_itr *itr)
{
- return i->e->v;
+ if (itr == NULL || itr->e == NULL)
+ return NULL;
+
+ return itr->e->v;
}
/*****************************************************************************/
free(itr);
- struct hashtable_itr *itr_remove = hashtable_iterator(remove);
unsigned int num_removed = 0;
- do
+ if (hashtable_count(remove) > 0)
{
- hashtable_remove(h, hashtable_iterator_key(itr_remove));
- num_removed++;
- }
- while (hashtable_iterator_advance(itr_remove));
+ struct hashtable_itr *itr_remove = hashtable_iterator(remove);
- free(itr_remove);
+ do
+ {
+ hashtable_remove(h, hashtable_iterator_key(itr_remove));
+ num_removed++;
+ }
+ while (hashtable_iterator_advance(itr_remove));
+
+ free(itr_remove);
+ }
hashtable_destroy(remove);