{
hashtItem *htip;
- htip = Safe_calloc (1, sizeof (hashtItem));
+ htip = Safe_alloc ( sizeof (hashtItem));
htip->key = key;
htip->pkey = pkey;
{
hTab *htab;
- htab = Safe_calloc (1, sizeof (hTab));
+ htab = Safe_alloc ( sizeof (hTab));
- if (!(htab->table = calloc ((size + 1), sizeof (hashtItem *))))
+ if (!(htab->table = Safe_alloc ((size + 1) * sizeof (hashtItem *))))
{
fprintf (stderr, "out of virtual memory %s %d\n",
__FILE__, (size + 1) * sizeof (hashtItem *));
jn = jc->next;
while (jc)
{
- free (jc);
+ Safe_free (jc);
if ((jc = jn))
jn = jc->next;
}
p->table[i] = NULL;
}
- free (p->table);
+ Safe_free (p->table);
}
}
hTabDeleteByKey (hTab ** h, int key, const void *pkey, int (*compare) (const void *, const void *))
{
hashtItem *htip, **htipp;
+ bool found = FALSE;
if (!(*h))
return 0;
pkey == htip->pkey)
{
*htipp = htip->next;
+ found = TRUE;
break;
}
htipp = &(htip->next);
}
- (*h)->nItems--;
- if (!(*h)->nItems)
+ if (found == TRUE)
{
- *h = NULL;
+ (*h)->nItems--;
+
+ if (!(*h)->nItems)
+ {
+ *h = NULL;
+ }
}
+
return 1;
}
/* First, delete any that currently exist */
hTabDeleteByKey (h, key, szKey, _compare);
/* Now add in ours */
- hTabAddItemLong (h, key, gc_strdup (szKey), gc_strdup (szValue));
+ hTabAddItemLong (h, key, Safe_strdup (szKey), Safe_strdup (szValue));
}
const char *