dovecot-1.2-sieve: Imap4flags extension: fixed bug in removeflag: removing a single flag failed due to off-by-one error.

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Wed Dec 30 05:44:41 EET 2009


details:   http://hg.rename-it.nl/dovecot-1.2-sieve/rev/9e18561e357f
changeset: 1168:9e18561e357f
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Wed Dec 30 04:43:02 2009 +0100
description:
Imap4flags extension: fixed bug in removeflag: removing a single flag failed due to off-by-one error.

diffstat:

 src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.c |  22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diffs (52 lines):

diff -r 1e42fa95f405 -r 9e18561e357f src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.c
--- a/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.c	Wed Dec 30 04:40:04 2009 +0100
+++ b/src/lib-sieve/plugins/imap4flags/ext-imap4flags-common.c	Wed Dec 30 04:43:02 2009 +0100
@@ -307,24 +307,34 @@
 	const unsigned char *fbegin;
 	const unsigned char *fstart;
 	const unsigned char *fend;
-	
+
+	/* Return if no more flags are available */	
 	if ( iter->offset >= len ) return NULL;
 	
+	/* Mark string boundries */
 	fbegin = str_data(iter->flags_list);
-	fp = fbegin + iter->offset;
-	fstart = fp;
 	fend = fbegin + len;
+
+	/* Start of this flag */
+	fstart = fbegin + iter->offset;
+
+	/* Scan for next flag */
+	fp = fstart;
 	for (;;) {
-		if ( fp >= fend || *fp == ' ' ) { 
+		/* Have we reached the end or a flag boundary? */
+		if ( fp >= fend || *fp == ' ' ) {
+			/* Did we scan more than nothing ? */
 			if ( fp > fstart ) {
+				/* Return flag */
 				const char *flag = t_strdup_until(fstart, fp);
 				
 				iter->last = fstart - fbegin;
 				iter->offset = fp - fbegin;
+
 				return flag;
 			} 	
 			
-			fstart = fp+1;
+			fstart = fp + 1;
 		}
 		
 		if ( fp >= fend ) break;
@@ -343,7 +353,7 @@
 	iter->offset++;
 	if ( iter->offset > str_len(iter->flags_list) )
 		iter->offset = str_len(iter->flags_list);
-	if ( iter->offset == str_len(iter->flags_list) )
+	if ( iter->offset == str_len(iter->flags_list) && iter->last > 0 )
 		iter->last--;
 
 	str_delete(iter->flags_list, iter->last, iter->offset - iter->last);	


More information about the dovecot-cvs mailing list