dovecot: Fixed assert-crash for sorting by strings.

dovecot at dovecot.org dovecot at dovecot.org
Sun Oct 28 12:37:33 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/119c5a16150c
changeset: 6644:119c5a16150c
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Oct 28 12:37:29 2007 +0200
description:
Fixed assert-crash for sorting by strings.

diffstat:

1 file changed, 9 insertions(+), 5 deletions(-)
src/lib-storage/index/index-sort.c |   14 +++++++++-----

diffs (41 lines):

diff -r 3240d834be16 -r 119c5a16150c src/lib-storage/index/index-sort.c
--- a/src/lib-storage/index/index-sort.c	Sun Oct 28 02:46:06 2007 +0300
+++ b/src/lib-storage/index/index-sort.c	Sun Oct 28 12:37:29 2007 +0200
@@ -416,7 +416,7 @@ index_sort_add_ids_range(struct mail_sea
 			   also between the first and the last messages */
 			skip = (last_id - prev_id) / (idx2 - i + 2);
 			nodes[i].sort_id = prev_id + skip;
-			if (nodes[i].sort_id == prev_id)
+			if (nodes[i].sort_id == prev_id && prev_id != last_id)
 				nodes[i].sort_id++;
 			if (nodes[i].sort_id == last_id) {
 				/* we ran out of ID space. have to renumber
@@ -442,12 +442,16 @@ index_sort_renumber_ids(struct mail_sear
 		(struct index_transaction_context *)program->t;
 	struct mail_sort_node *nodes;
 	unsigned int i, count;
-	uint32_t sort_id, prev_sort_id, skip;
+	uint32_t sort_id = 0, prev_sort_id, skip;
 
 	nodes = array_get_modifiable(&program->all_nodes, &count);
 	prev_sort_id = (uint32_t)-1;
-	sort_id = nodes[idx].sort_id;
-	i_assert(sort_id == nodes[idx + 1].sort_id);
+	for (; idx < count; idx++) {
+		sort_id = nodes[idx].sort_id;
+		if (sort_id == nodes[idx+1].sort_id)
+			break;
+	}
+	i_assert(idx != count);
 
 	if (((uint32_t)-1 - sort_id) / (count - idx + 1) < RENUMBER_SPACE) {
 		/* space is running out, lets just renumber everything */
@@ -501,7 +505,7 @@ index_sort_add_ids(struct mail_search_so
 			if (index_sort_add_ids_range(program, mail,
 						     i == 0 ? 0 : i-1,
 						     I_MIN(j, count-1)) == 0)
-				index_sort_renumber_ids(program, i);
+				index_sort_renumber_ids(program, i-1);
 		}
 	}
 }


More information about the dovecot-cvs mailing list