hash.c: use xalloc
This commit is contained in:
parent
891e438a7a
commit
e78f8bea4d
2 changed files with 5 additions and 4 deletions
2
Makefile
2
Makefile
|
|
@ -15,7 +15,7 @@ install : $(PROGRAMS)
|
||||||
cp $^ $(HOME)/bin/
|
cp $^ $(HOME)/bin/
|
||||||
|
|
||||||
dlight : dlight.o buffer.o env.o http.o rss.o lockfile.o filter.o cconf.o \
|
dlight : dlight.o buffer.o env.o http.o rss.o lockfile.o filter.o cconf.o \
|
||||||
proc-cache.o dlhist.o hash.o error.o
|
proc-cache.o dlhist.o hash.o xalloc.o error.o
|
||||||
dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o \
|
dlight-compile : compile.o buffer.o env.o lockfile.o filter.o cconf.o \
|
||||||
error.o
|
error.o
|
||||||
dlight-read-config : read-config.o buffer.o env.o cconf.o error.o
|
dlight-read-config : read-config.o buffer.o env.o cconf.o error.o
|
||||||
|
|
|
||||||
7
hash.c
7
hash.c
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
#include "xalloc.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define TABLE_MIN_SIZE 128
|
#define TABLE_MIN_SIZE 128
|
||||||
|
|
@ -42,7 +43,7 @@ void hash_init(struct hash_table *table) {
|
||||||
void hash_free(struct hash_table *table) {
|
void hash_free(struct hash_table *table) {
|
||||||
|
|
||||||
if (table->ptr)
|
if (table->ptr)
|
||||||
free(table->ptr);
|
xfree(table->ptr);
|
||||||
hash_init(table);
|
hash_init(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +104,7 @@ static void resize(struct hash_table *t) {
|
||||||
t->size = TABLE_MIN_SIZE;
|
t->size = TABLE_MIN_SIZE;
|
||||||
|
|
||||||
t->count = 0;
|
t->count = 0;
|
||||||
t->ptr = calloc(sizeof(t->ptr), t->size);
|
t->ptr = xmallocz(sizeof(t->ptr) * t->size);
|
||||||
|
|
||||||
if (old) {
|
if (old) {
|
||||||
for(i=0; i < old_size; i++) {
|
for(i=0; i < old_size; i++) {
|
||||||
|
|
@ -111,7 +112,7 @@ static void resize(struct hash_table *t) {
|
||||||
if (entry)
|
if (entry)
|
||||||
insert(t, *entry, entry);
|
insert(t, *entry, entry);
|
||||||
}
|
}
|
||||||
free(old);
|
xfree(old);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue