aboutsummaryrefslogtreecommitdiffstats
path: root/libibex
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-10-10 20:26:29 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-10-10 20:26:29 +0800
commit895793d1dd3162f8b3d765a7712b8267aa88a40f (patch)
tree45f2c5246b9cca3d80b5f298d4b6686e374db385 /libibex
parent80a69b39bdbbe56eb60b8a29a15a57e1ddbda922 (diff)
downloadgsoc2013-evolution-895793d1dd3162f8b3d765a7712b8267aa88a40f.tar
gsoc2013-evolution-895793d1dd3162f8b3d765a7712b8267aa88a40f.tar.gz
gsoc2013-evolution-895793d1dd3162f8b3d765a7712b8267aa88a40f.tar.bz2
gsoc2013-evolution-895793d1dd3162f8b3d765a7712b8267aa88a40f.tar.lz
gsoc2013-evolution-895793d1dd3162f8b3d765a7712b8267aa88a40f.tar.xz
gsoc2013-evolution-895793d1dd3162f8b3d765a7712b8267aa88a40f.tar.zst
gsoc2013-evolution-895793d1dd3162f8b3d765a7712b8267aa88a40f.zip
Truncate key if it is too big to fit in a single block to MAX_KEYLEN
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. svn path=/trunk/; revision=5815
Diffstat (limited to 'libibex')
-rw-r--r--libibex/ChangeLog7
-rw-r--r--libibex/hash.c15
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);