]> andersk Git - moira.git/commitdiff
detect running out of memory
authormar <mar>
Tue, 5 Dec 1989 18:33:02 +0000 (18:33 +0000)
committermar <mar>
Tue, 5 Dec 1989 18:33:02 +0000 (18:33 +0000)
lib/hash.c

index aedd5e46f6c9b1d4fa99cf4dd6470e8545d09da5..c6cef7eefbf2a047d24e0e83dbf26c07b80055e7 100644 (file)
@@ -22,8 +22,14 @@ int size;
     struct hash *h;
 
     h = (struct hash *) malloc(sizeof(struct hash));
+    if (h == (struct hash *) NULL)
+      return((struct hash *) NULL);
     h->size = size;
     h->data = (struct bucket **) malloc(size * sizeof(char *));
+    if (h->data == (struct bucket **) NULL) {
+       free(h);
+       return((struct hash *) NULL);
+    }
     bzero(h->data, size * sizeof(char *));
     return(h);
 }
@@ -71,7 +77,7 @@ char *value;
 
 
 /* Store an item in the hash table.  Returns 0 if the key was not previously
- * there, or 1 if it was.
+ * there, 1 if it was, or -1 if we ran out of memory.
  */
 
 int hash_store(h, key, value)
@@ -84,6 +90,8 @@ char *value;
     p = &(h->data[hash_func(h, key)]);
     if (*p == NULL) {
        b = *p = (struct bucket *) malloc(sizeof(struct bucket));
+       if (b == (struct bucket *) NULL)
+         return(-1);
        b->next = NULL;
        b->key = key;
        b->data = value;
@@ -97,6 +105,8 @@ char *value;
        return(1);
     }
     b = *p = (struct bucket *) malloc(sizeof(struct bucket));
+    if (b == (struct bucket *) NULL)
+      return(-1);
     b->next = NULL;
     b->key = key;
     b->data = value;
This page took 0.040268 seconds and 5 git commands to generate.