changeset 4520:da2d2146a419 HEAD

Fixed dictionary iteration.
author Timo Sirainen <tss@iki.fi>
date Mon, 31 Jul 2006 02:04:18 +0300
parents 4be4c887deb7
children 9202ffe3d5c5
files src/lib-dict/dict-db.c
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-dict/dict-db.c	Mon Jul 31 02:03:58 2006 +0300
+++ b/src/lib-dict/dict-db.c	Mon Jul 31 02:04:18 2006 +0300
@@ -23,6 +23,7 @@
 
 	DBC *cursor;
 	char *path;
+	unsigned int path_len;
 
 	DBT pkey, pdata;
 
@@ -243,16 +244,19 @@
 						  &ctx->pkey, &ctx->pdata,
 						  DB_NEXT)) == 0) {
 			/* make sure the path matches */
-			if (ctx->path == NULL ||
+			if (ctx->path == NULL)
+				break;
+			if (ctx->path_len <= ctx->pkey.size &&
 			    strncmp(ctx->path, ctx->pkey.data,
-				    ctx->pkey.size) == 0)
+				    ctx->path_len) == 0)
 				break;
 		}
 	} else {
 		ret = ctx->cursor->c_get(ctx->cursor, &ctx->pkey, &ctx->pdata,
 					 DB_NEXT);
 		if (ctx->path != NULL && ret == 0 &&
-		    strncmp(ctx->path, ctx->pkey.data, ctx->pkey.size) != 0) {
+		    (ctx->path_len > ctx->pkey.size ||
+		     strncmp(ctx->path, ctx->pkey.data, ctx->path_len) != 0)) {
 			/* there are no more matches */
 			return 0;
 		}
@@ -301,6 +305,7 @@
 	ctx->ctx.dict = _dict;
 	ctx->flags = flags;
 	ctx->path = i_strdup_empty(path);
+	ctx->path_len = ctx->path == NULL ? 0 : strlen(ctx->path);
 	
 	ctx->iterate_next = db_dict_iterate_first;
 	return &ctx->ctx;