diff options
author | Tor Andersson <tor@ghostscript.com> | 2004-10-06 11:36:25 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2004-10-06 11:36:25 +0200 |
commit | 59bd2f5bfc486b107c4bd689bd65ea7d23e2fad0 (patch) | |
tree | 2331c04f638f4144eb26163d7585f54dd5542876 /base/hash.c | |
parent | 57575cabd50c4fdadb7de8ed5dec5702be7c3954 (diff) | |
download | mupdf-59bd2f5bfc486b107c4bd689bd65ea7d23e2fad0.tar.xz |
hashtable and object store memory bugs
Diffstat (limited to 'base/hash.c')
-rw-r--r-- | base/hash.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/base/hash.c b/base/hash.c index 24d49ab5..962b92e1 100644 --- a/base/hash.c +++ b/base/hash.c @@ -23,9 +23,9 @@ struct fz_hashentry_s struct fz_hashtable_s { - unsigned keylen; - unsigned size; - unsigned load; + int keylen; + int size; + int load; fz_hashentry *ents; }; @@ -80,13 +80,13 @@ fz_hashlen(fz_hashtable *table) } void * -fz_gethashkey(fz_hashtable *table, int idx) +fz_hashgetkey(fz_hashtable *table, int idx) { return table->ents[idx].key; } void * -fz_gethashval(fz_hashtable *table, int idx) +fz_hashgetval(fz_hashtable *table, int idx) { return table->ents[idx].val; } @@ -104,9 +104,9 @@ fz_resizehash(fz_hashtable *table, int newsize) fz_error *error; fz_hashentry *newents; fz_hashentry *oldents; - unsigned oldload; - unsigned oldsize; - unsigned i; + int oldload; + int oldsize; + int i; oldsize = table->size; oldload = table->load; @@ -115,7 +115,7 @@ fz_resizehash(fz_hashtable *table, int newsize) if (newsize < oldload * 8 / 10) return fz_throw("rangecheck: resize hash too small"); - newents = fz_realloc(table->ents, sizeof(fz_hashentry) * newsize); + newents = fz_malloc(sizeof(fz_hashentry) * newsize); if (!newents) return fz_outofmem; @@ -167,9 +167,9 @@ fz_error * fz_hashinsert(fz_hashtable *table, void *key, void *val) { fz_error *error; - fz_hashentry *ents = table->ents; - unsigned size = table->size; - unsigned pos = hash(key, table->keylen) % size; + fz_hashentry *ents; + unsigned size; + unsigned pos; if (table->load > table->size * 8 / 10) { @@ -178,6 +178,10 @@ fz_hashinsert(fz_hashtable *table, void *key, void *val) return error; } + ents = table->ents; + size = table->size; + pos = hash(key, table->keylen) % size; + while (1) { if (!ents[pos].val) |