Author: rjek
Date: Sun Aug 20 14:46:30 2006
New Revision: 2872
URL:
http://svn.semichrome.net?rev=2872&view=rev
Log:
Make hash_add() return success/failure bool
Modified:
trunk/netsurf/utils/hashtable.c
trunk/netsurf/utils/hashtable.h
Modified: trunk/netsurf/utils/hashtable.c
URL:
http://svn.semichrome.net/trunk/netsurf/utils/hashtable.c?rev=2872&r1...
==============================================================================
--- trunk/netsurf/utils/hashtable.c (original)
+++ trunk/netsurf/utils/hashtable.c Sun Aug 20 14:46:30 2006
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
+#include <stdbool.h>
#ifdef TEST_RIG
#include <assert.h>
#include <stdio.h>
@@ -60,7 +61,7 @@
free(ht);
}
-void hash_add(struct hash_table *ht, const char *key, const char *value)
+bool hash_add(struct hash_table *ht, const char *key, const char *value)
{
unsigned int h = hash_string_fnv(key);
unsigned int c = h % ht->nchains;
@@ -68,9 +69,24 @@
sizeof(struct hash_entry));
e->key = strdup(key);
+ if (e->key == NULL) {
+ LOG(("Unable to strdup() key for hash table."));
+ free(e);
+ return false;
+ }
+
e->value = strdup(value);
+ if (e->value == NULL) {
+ LOG(("Unable to strdup() value for hash table."));
+ free(e->key);
+ free(e);
+ return false;
+ }
+
e->next = ht->chain[c];
ht->chain[c] = e;
+
+ return true;
}
const char *hash_get(struct hash_table *ht, const char *key)
Modified: trunk/netsurf/utils/hashtable.h
URL:
http://svn.semichrome.net/trunk/netsurf/utils/hashtable.h?rev=2872&r1...
==============================================================================
--- trunk/netsurf/utils/hashtable.h (original)
+++ trunk/netsurf/utils/hashtable.h Sun Aug 20 14:46:30 2006
@@ -9,6 +9,8 @@
#ifndef _NETSURF_HASH_H_
#define _NETSURF_HASH_H_
+
+#include <stdbool.h>
struct hash_entry {
char *key;
@@ -23,7 +25,7 @@
struct hash_table *hash_create(unsigned int chains);
void hash_destroy(struct hash_table *ht);
-void hash_add(struct hash_table *ht, const char *key, const char *value);
+bool hash_add(struct hash_table *ht, const char *key, const char *value);
const char *hash_get(struct hash_table *ht, const char *key);
unsigned int hash_string_fnv(const char *datum);