dovecot-2.2: dsync: Avoid possibly long function recursion.

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 16 08:01:21 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/516a337480f4
changeset: 15770:516a337480f4
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Feb 16 08:01:10 2013 +0200
description:
dsync: Avoid possibly long function recursion.

diffstat:

 src/doveadm/dsync/dsync-mailbox-import.c |  40 ++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 17 deletions(-)

diffs (79 lines):

diff -r 77ef526e6a0a -r 516a337480f4 src/doveadm/dsync/dsync-mailbox-import.c
--- a/src/doveadm/dsync/dsync-mailbox-import.c	Sat Feb 16 08:00:51 2013 +0200
+++ b/src/doveadm/dsync/dsync-mailbox-import.c	Sat Feb 16 08:01:10 2013 +0200
@@ -227,15 +227,16 @@
 	return memcmp(change_guid_128, guid_128, GUID_128_SIZE) == 0;
 }
 
-static bool
-importer_next_mail(struct dsync_mailbox_importer *importer, uint32_t wanted_uid)
+static int
+importer_try_next_mail(struct dsync_mailbox_importer *importer,
+		       uint32_t wanted_uid)
 {
+	struct mail_private *pmail;
 	const char *hdr_hash;
-	int ret = 0;
 
 	if (importer->cur_mail == NULL) {
 		/* end of search */
-		return FALSE;
+		return -1;
 	}
 	while (importer->cur_mail->seq < importer->next_local_seq ||
 	       importer->cur_mail->uid < wanted_uid) {
@@ -254,7 +255,7 @@
 			importer->cur_mail = NULL;
 			importer->cur_guid = NULL;
 			importer->cur_hdr_hash = NULL;
-			return FALSE;
+			return -1;
 		}
 		importer->cur_uid_has_change = FALSE;
 	}
@@ -264,28 +265,33 @@
 		if (mail_get_special(importer->cur_mail, MAIL_FETCH_GUID,
 				     &importer->cur_guid) < 0) {
 			dsync_mail_error(importer, importer->cur_mail, "GUID");
-			ret = -1;
+			return 0;
 		}
 	} else {
 		if (dsync_mail_get_hdr_hash(importer->cur_mail,
 					    &hdr_hash) < 0) {
 			dsync_mail_error(importer, importer->cur_mail,
 					 "header hash");
-			ret = -1;
-		} else {
-			struct mail_private *pmail =
-				(struct mail_private *)importer->cur_mail;
-			importer->cur_hdr_hash = p_strdup(pmail->pool, hdr_hash);
-		}
-	}
-	if (ret < 0) {
-		importer->next_local_seq = importer->cur_mail->seq + 1;
-		return importer_next_mail(importer, wanted_uid);
+			return 0;
+		} 
+		pmail = (struct mail_private *)importer->cur_mail;
+		importer->cur_hdr_hash = p_strdup(pmail->pool, hdr_hash);
 	}
 	/* make sure next_local_seq gets updated in case we came here
 	   because of min_uid */
 	importer->next_local_seq = importer->cur_mail->seq;
-	return TRUE;
+	return 1;
+}
+
+static bool
+importer_next_mail(struct dsync_mailbox_importer *importer, uint32_t wanted_uid)
+{
+	int ret;
+
+	while ((ret = importer_try_next_mail(importer, wanted_uid)) == 0 &&
+	       !importer->failed)
+		importer->next_local_seq = importer->cur_mail->seq + 1;
+	return ret > 0;
 }
 
 static int


More information about the dovecot-cvs mailing list