[dovecot-cvs] dovecot/src/lib-dict dict-db.c,1.2,1.3

cras at dovecot.org cras at dovecot.org
Mon Jul 31 02:04:20 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-dict
In directory talvi:/tmp/cvs-serv11819

Modified Files:
	dict-db.c 
Log Message:
Fixed dictionary iteration.



Index: dict-db.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-dict/dict-db.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dict-db.c	30 Jul 2006 19:27:26 -0000	1.2
+++ dict-db.c	30 Jul 2006 23:04:18 -0000	1.3
@@ -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;



More information about the dovecot-cvs mailing list