changeset 46:b2bc8d2e56ff HEAD

fixes for messageset handling
author Timo Sirainen <tss@iki.fi>
date Tue, 27 Aug 2002 06:28:07 +0300
parents d8ff9a34ed03
children 306c20092a96
files src/lib-storage/index/index-search.c
diffstat 1 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-search.c	Tue Aug 27 06:26:18 2002 +0300
+++ b/src/lib-storage/index/index-search.c	Tue Aug 27 06:28:07 2002 +0300
@@ -98,6 +98,23 @@
 	return FALSE;
 }
 
+static off_t str_to_off_t(const char *str)
+{
+	off_t num;
+
+	num = 0;
+	while (*str != '\0') {
+		if (*str < '0' || *str > '9')
+			return -1;
+
+		/* FIXME: this may overflow, and ANSI-C says overflowing
+		   signed values have undefined behaviour.. */
+		num = num*10 + *str - '0';
+	}
+
+	return num;
+}
+
 /* Returns >0 = matched, 0 = not matched, -1 = unknown */
 static int search_arg_match_index(IndexMailbox *ibox, MailIndexRecord *rec,
 				  unsigned int seq, MailSearchArgType type,
@@ -163,9 +180,9 @@
 
 	/* sizes */
 	case SEARCH_SMALLER:
-		return rec->full_virtual_size < strtoul(value, NULL, 10);
+		return rec->full_virtual_size < str_to_off_t(value);
 	case SEARCH_LARGER:
-		return rec->full_virtual_size > strtoul(value, NULL, 10);
+		return rec->full_virtual_size > str_to_off_t(value);
 
 	default:
 		return -1;
@@ -529,7 +546,7 @@
 				*last_seq = seq;
 		}
 
-		seq++;
+		set++;
 	}
 }
 
@@ -611,6 +628,11 @@
 	/* see if we can limit the records we look at */
 	search_get_sequences(ibox, args, &first_seq, &last_seq);
 
+	if (first_seq > last_seq) {
+		/* not possible */
+		return;
+	}
+
 	ctx.ibox = ibox;
 
 	rec = ibox->index->lookup(ibox->index, first_seq);