git » nmdb » commit 7af1ac6

nmdb: Properly limit the cache chain length

author Alberto Bertogli
2010-04-09 15:44:07 UTC
committer Alberto Bertogli
2010-04-09 15:44:07 UTC
parent 2bf5811c9ba1c4b291e5fa7871d07fec4fa7ddb5

nmdb: Properly limit the cache chain length

cache_set() was using a wrong comparison operator (<= instead of <), and it
made the chain length one more than it should.

Luckily it didn't cause crashes or misbehaviour.

Bug reported and patch provided by 刘知言 <lzy.dev@gmail.com>.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

nmdb/cache.c +1 -1

diff --git a/nmdb/cache.c b/nmdb/cache.c
index 71f2f93..22c12ba 100644
--- a/nmdb/cache.c
+++ b/nmdb/cache.c
@@ -215,7 +215,7 @@ int cache_set(struct cache *cd, const unsigned char *key, size_t ksize,
 			c->first = new;
 			c->last = new;
 			c->len = 1;
-		} else if (c->len <= cd->chainlen) {
+		} else if (c->len < cd->chainlen) {
 			/* slots are still available, put the entry first */
 			new->next = c->first;
 			c->first->prev = new;