summaryrefslogtreecommitdiff
path: root/utils/hashtable.c
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2006-08-20 16:02:22 +0000
committerJames Bursa <james@netsurf-browser.org>2006-08-20 16:02:22 +0000
commitefb9fd036bd5e7586d3afd7e27c851bfb9fe315e (patch)
treeb1f527748e7d6f42c48dae517a27c3dd11e86389 /utils/hashtable.c
parent1f9fed85566a8eac647f0cd62db5380113ea0ef0 (diff)
downloadnetsurf-efb9fd036bd5e7586d3afd7e27c851bfb9fe315e.tar.gz
netsurf-efb9fd036bd5e7586d3afd7e27c851bfb9fe315e.tar.bz2
Check for malloc failing in hash_add(). Remove unnecessary casts.
svn path=/trunk/netsurf/; revision=2873
Diffstat (limited to 'utils/hashtable.c')
-rw-r--r--utils/hashtable.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/utils/hashtable.c b/utils/hashtable.c
index d34b19960..51ed0c330 100644
--- a/utils/hashtable.c
+++ b/utils/hashtable.c
@@ -5,7 +5,8 @@
* Copyright 2006 Rob Kendrick <rjek@rjek.com>
*/
-/** Write-Once hash table for string to string mappings */
+/** \file
+ * Write-Once hash table for string to string mappings */
#include <stdlib.h>
#include <string.h>
@@ -19,8 +20,7 @@
struct hash_table *hash_create(unsigned int chains)
{
- struct hash_table *r = (struct hash_table *)malloc(
- sizeof(struct hash_table));
+ struct hash_table *r = malloc(sizeof(struct hash_table));
if (r == NULL) {
LOG(("Not enough memory for hash table."));
@@ -28,8 +28,7 @@ struct hash_table *hash_create(unsigned int chains)
}
r->nchains = chains;
- r->chain = (struct hash_entry **)
- calloc(chains, sizeof(struct hash_entry));
+ r->chain = calloc(chains, sizeof(struct hash_entry));
if (r->chain == NULL) {
LOG(("Not enough memory for %d hash table chains.", chains));
@@ -42,7 +41,7 @@ struct hash_table *hash_create(unsigned int chains)
void hash_destroy(struct hash_table *ht)
{
- int i;
+ unsigned int i;
for (i = 0; i < ht->nchains; i++) {
if (ht->chain[i] != NULL) {
@@ -65,8 +64,11 @@ 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;
- struct hash_entry *e = (struct hash_entry *)malloc(
- sizeof(struct hash_entry));
+ struct hash_entry *e = malloc(sizeof(struct hash_entry));
+ if (e == NULL) {
+ LOG(("Not enough memory for hash entry."));
+ return false;
+ }
e->key = strdup(key);
if (e->key == NULL) {