void *Next;
const char* KeyStr;
+ if (Hash == NULL)
+ return 0;
+
for (i=0; i < Hash->nMembersUsed; i++) {
if (i==0) {
Previous = NULL;
const char *bla = "";
long key;
long i;
+
+ if (Hash == NULL)
+ return 0;
+
if (Hash->MyKeys != NULL)
free (Hash->MyKeys);
foo = Hash->LookupTable[i]->HashKey;
if (First != NULL)
bar = First(Hash->Members[Hash->LookupTable[i]->Position]->Data);
+ else
+ bar = "";
if (Second != NULL)
bla = Second(Hash->Members[Hash->LookupTable[i]->Position]->Data);
+ else
+ bla = "";
}
#ifdef DEBUG
printf (" ---- Hashkey[%ld][%ld]: '%s' Value: '%s' ; %s\n", i, key, foo, bar, bla);
/**
* \brief private destructor for one hash element.
+ * Crashing? go one frame up and do 'print *FreeMe->LookupTable[i]'
* \param Data an element to free using the user provided destructor, or just plain free
*/
static void DeleteHashPayload (Payload *Data)
free(Data->Data);
}
+/**
+ * \brief Destructor for nested hashes
+ */
+void HDeleteHash(void *vHash)
+{
+ HashList *FreeMe = (HashList*)vHash;
+ DeleteHash(&FreeMe);
+}
+
/**
* \brief destroy a hashlist and all of its members
+ * Crashing? do 'print *FreeMe->LookupTable[i]'
* \param Hash Hash to destroy. Is NULL'ed so you are shure its done.
*/
void DeleteHash(HashList **Hash)
Payload **NewPayloadArea;
HashKey **NewTable;
+ if (Hash == NULL)
+ return ;
+
/** double our payload area */
NewPayloadArea = (Payload**) malloc(sizeof(Payload*) * Hash->MemberSize * 2);
memset(&NewPayloadArea[Hash->MemberSize], 0, sizeof(Payload*) * Hash->MemberSize);
Payload *NewPayloadItem;
HashKey *NewHashKey;
+ if (Hash == NULL)
+ return;
+
if (Hash->nMembersUsed >= Hash->MemberSize)
IncreaseHashSize (Hash);
{
long SearchPos;
+ if (Hash == NULL)
+ return 0;
+
for (SearchPos = 0; SearchPos < Hash->nMembersUsed; SearchPos ++) {
if (Hash->LookupTable[SearchPos]->Key == HashBinKey){
return SearchPos;
long SearchPos;
long StepWidth;
+ if (Hash == NULL)
+ return 0;
+
if (Hash->tainted)
return FindInTaintedHash(Hash, HashBinKey);
*/
inline static long CalcHashKey (HashList *Hash, const char *HKey, long HKLen)
{
+ if (Hash == NULL)
+ return 0;
+
if (Hash->Algorithm == NULL)
return hashlittle(HKey, HKLen, 9283457);
else
long HashBinKey;
long HashAt;
+ if (Hash == NULL)
+ return;
+
/** first, find out were we could fit in... */
HashBinKey = CalcHashKey(Hash, HKey, HKLen);
HashAt = FindInHash(Hash, HashBinKey);
long HashBinKey;
long HashAt;
+ if (Hash == NULL)
+ return 0;
+
if (HKLen <= 0) {
*Data = NULL;
return 0;
int GetHashKeys(HashList *Hash, char ***List)
{
long i;
+ if (Hash == NULL)
+ return 0;
if (Hash->MyKeys != NULL)
free (Hash->MyKeys);
*/
void DeleteHashPos(HashPos **DelMe)
{
- free(*DelMe);
- *DelMe = NULL;
+ if (*DelMe != NULL)
+ {
+ free(*DelMe);
+ *DelMe = NULL;
+ }
}
* \param Data returns the Data found at HashPos
* \returns whether the item was found or not.
*/
-int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, char **HashKey, void **Data)
+int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data)
{
long PayloadPos;
- if (Hash->nMembersUsed <= At->Position)
+ if ((Hash == NULL) || (Hash->nMembersUsed <= At->Position))
return 0;
*HKLen = Hash->LookupTable[At->Position]->HKLen;
*HashKey = Hash->LookupTable[At->Position]->HashKey;
* return strcmp (a, b);
* }
*/
+
+
+/*
+ * Generic function to free a pointer. This can be used as a callback with the
+ * hash table, even on systems where free() is defined as a macro or has had other
+ * horrible things done to it.
+ */
+void generic_free_handler(void *ptr) {
+ free(ptr);
+}
+
+
+