# HG changeset patch # User Timo Sirainen # Date 1030418887 -10800 # Node ID b2bc8d2e56ff6e756cea89342ad85fac9d364094 # Parent d8ff9a34ed0326d219c8a6b01f8cc63e9bdcacd8 fixes for messageset handling diff -r d8ff9a34ed03 -r b2bc8d2e56ff src/lib-storage/index/index-search.c --- 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);