dovecot-2.0: lib-index: Small code cleanup.

dovecot at dovecot.org dovecot at dovecot.org
Mon Apr 5 09:18:17 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/7d76f4a9c5c8
changeset: 11072:7d76f4a9c5c8
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Apr 05 09:16:56 2010 +0300
description:
lib-index: Small code cleanup.

diffstat:

 src/lib-index/mail-index-map.c |  62 +++++++++++++++++++------------
 1 files changed, 38 insertions(+), 24 deletions(-)

diffs (83 lines):

diff -r d61ffd81124c -r 7d76f4a9c5c8 src/lib-index/mail-index-map.c
--- a/src/lib-index/mail-index-map.c	Mon Apr 05 09:13:55 2010 +0300
+++ b/src/lib-index/mail-index-map.c	Mon Apr 05 09:16:56 2010 +0300
@@ -152,12 +152,44 @@
 	return 0;
 }
 
+static int
+mail_index_map_ext_hdr_check_record(const struct mail_index_header *hdr,
+				    const struct mail_index_ext_header *ext_hdr,
+				    const char **error_r)
+{
+	if (ext_hdr->record_align == 0) {
+		*error_r = "Record field alignment is zero";
+		return -1;
+	}
+
+	if (ext_hdr->record_offset + ext_hdr->record_size > hdr->record_size) {
+		*error_r = t_strdup_printf("Record field points "
+					   "outside record size (%u+%u > %u)",
+					   ext_hdr->record_offset,
+					   ext_hdr->record_size,
+					   hdr->record_size);
+		return -1;
+	}
+
+	if ((ext_hdr->record_offset % ext_hdr->record_align) != 0) {
+		*error_r = t_strdup_printf("Record field alignment %u "
+					   "not used", ext_hdr->record_align);
+		return -1;
+	}
+	if ((hdr->record_size % ext_hdr->record_align) != 0) {
+		*error_r = t_strdup_printf("Record size not aligned by %u "
+					   "as required by extension",
+					   ext_hdr->record_align);
+		return -1;
+	}
+	return 0;
+}
+
 int mail_index_map_ext_hdr_check(const struct mail_index_header *hdr,
 				 const struct mail_index_ext_header *ext_hdr,
 				 const char *name, const char **error_r)
 {
-	if ((ext_hdr->record_size == 0 && ext_hdr->hdr_size == 0) ||
-	    (ext_hdr->record_align == 0 && ext_hdr->record_size != 0)) {
+	if (ext_hdr->record_size == 0 && ext_hdr->hdr_size == 0) {
 		*error_r = "Invalid field values";
 		return -1;
 	}
@@ -168,28 +200,10 @@
 
 	/* if we get here from extension introduction, record_offset=0 and
 	   hdr->record_size hasn't been updated yet */
-	if (ext_hdr->record_offset != 0 &&
-	    ext_hdr->record_offset + ext_hdr->record_size > hdr->record_size) {
-		*error_r = t_strdup_printf("Record field points "
-					   "outside record size (%u+%u > %u)",
-					   ext_hdr->record_offset,
-					   ext_hdr->record_size,
-					   hdr->record_size);
-		return -1;
-	}
-
-	if (ext_hdr->record_size > 0 &&
-	    (ext_hdr->record_offset % ext_hdr->record_align) != 0) {
-		*error_r = t_strdup_printf("Record field alignment %u "
-					   "not used", ext_hdr->record_align);
-		return -1;
-	}
-	if (ext_hdr->record_offset != 0 &&
-	    (hdr->record_size % ext_hdr->record_align) != 0) {
-		*error_r = t_strdup_printf("Record size not aligned by %u "
-					   "as required by extension",
-					   ext_hdr->record_align);
-		return -1;
+	if (ext_hdr->record_offset != 0 && ext_hdr->record_size != 0) {
+		if (mail_index_map_ext_hdr_check_record(hdr, ext_hdr,
+							error_r) < 0)
+			return -1;
 	}
 	if (ext_hdr->hdr_size > MAIL_INDEX_EXT_HEADER_MAX_SIZE) {
 		*error_r = t_strdup_printf("Headersize too large (%u)",


More information about the dovecot-cvs mailing list