summaryrefslogtreecommitdiff
path: root/base/hash.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2004-10-06 11:36:25 +0200
committerTor Andersson <tor@ghostscript.com>2004-10-06 11:36:25 +0200
commit59bd2f5bfc486b107c4bd689bd65ea7d23e2fad0 (patch)
tree2331c04f638f4144eb26163d7585f54dd5542876 /base/hash.c
parent57575cabd50c4fdadb7de8ed5dec5702be7c3954 (diff)
downloadmupdf-59bd2f5bfc486b107c4bd689bd65ea7d23e2fad0.tar.xz
hashtable and object store memory bugs
Diffstat (limited to 'base/hash.c')
-rw-r--r--base/hash.c28
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)