diff options
-rw-r--r-- | libibex/ChangeLog | 7 | ||||
-rw-r--r-- | libibex/hash.c | 15 |
2 files changed, 22 insertions, 0 deletions
diff --git a/libibex/ChangeLog b/libibex/ChangeLog index 5e16a0666b..50aed83023 100644 --- a/libibex/ChangeLog +++ b/libibex/ChangeLog @@ -1,3 +1,10 @@ +2000-10-10 Not Zed <NotZed@HelixCode.com> + + * hash.c (hash_find): + (hash_remove): + (hash_insert): Truncate key if it is too big to fit in a + single block to MAX_KEYLEN bytes. + 2000-09-28 Not Zed <NotZed@HelixCode.com> * block.c (ibex_block_free): Make sure we map the 'free' block to diff --git a/libibex/hash.c b/libibex/hash.c index 02e01a1ae0..a36bef33b0 100644 --- a/libibex/hash.c +++ b/libibex/hash.c @@ -86,6 +86,9 @@ struct _hashblock { #define hb_keys hashblock_u.keys #define hb_keydata hashblock_u.keydata +/* size of block overhead + 2 key block overhead */ +#define MAX_KEYLEN (BLOCK_SIZE - 4 - 12 - 12) + /* root block for a hash index */ struct _hashroot { hashid_t free; /* free list */ @@ -241,6 +244,10 @@ hash_find(struct _IBEXIndex *index, const char *key, int keylen) d(printf("finding hash %.*s\n", keylen, key)); + /* truncate the key to the maximum size */ + if (keylen > MAX_KEYLEN) + keylen = MAX_KEYLEN; + hashroot = (struct _hashroot *)ibex_block_read(index->blocks, index->root); /* find the table containing this entry */ @@ -353,6 +360,10 @@ hash_remove(struct _IBEXIndex *index, const char *key, int keylen) d(printf("removing hash %.*s\n", keylen, key)); + /* truncate the key to the maximum size */ + if (keylen > MAX_KEYLEN) + keylen = MAX_KEYLEN; + hashroot = (struct _hashroot *)ibex_block_read(index->blocks, index->root); /* find the table containing this entry */ @@ -475,6 +486,10 @@ hash_insert(struct _IBEXIndex *index, const char *key, int keylen) g_assert(index != 0); g_assert(index->root != 0); + /* truncate the key to the maximum size */ + if (keylen > MAX_KEYLEN) + keylen = MAX_KEYLEN; + d(printf("inserting hash %.*s\n", keylen, key)); hashroot = (struct _hashroot *)ibex_block_read(index->blocks, index->root); |