isync

mailbox synchronization program
git clone https://git.code.sf.net/p/isync/isync
Log | Files | Refs | README | LICENSE

commit e2d3b4d55b36b252d19d0c8b77e2ea59db7e4cd3
parent cc176df2c3b46d2becb6dd7c8ccc441471c468cb
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date:   Wed,  8 Jul 2020 17:27:37 +0200

fix lots of sign conversion warnings

... by making a lot of objects unsigned, and some signed.
casts which lose precision and change the sign in one go (ssize_t and
time_t to uint on LP64) are made explicit as well.

Diffstat:
Msrc/common.h | 22+++++++++++-----------
Msrc/config.c | 21+++++++++++----------
Msrc/config.h | 2+-
Msrc/driver.c | 4++--
Msrc/driver.h | 12++++++------
Msrc/drv_imap.c | 95++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/drv_maildir.c | 95++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/drv_proxy.c | 16++++++++--------
Msrc/main.c | 9+++++----
Msrc/socket.c | 58+++++++++++++++++++++++++++++++---------------------------
Msrc/socket.h | 18+++++++++---------
Msrc/sync.c | 47++++++++++++++++++++++++-----------------------
Msrc/sync.h | 2+-
Msrc/util.c | 52+++++++++++++++++++++++++---------------------------
14 files changed, 230 insertions(+), 223 deletions(-)

diff --git a/src/common.h b/src/common.h @@ -41,7 +41,7 @@ typedef unsigned long ulong; #define stringify(x) stringify__(x) #define shifted_bit(in, from, to) \ - (((uint)(in) / (from > to ? from / to : 1) * (to > from ? to / from : 1)) & to) + ((int)(((uint)(in) / (from > to ? from / to : 1) * (to > from ? to / from : 1)) & to)) #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) # define ATTR_UNUSED __attribute__((unused)) @@ -112,7 +112,7 @@ extern int Pid; extern char Hostname[256]; extern const char *Home; -extern int BufferLimit; +extern uint BufferLimit; extern int new_total[2], new_done[2]; extern int flags_total[2], flags_done[2]; @@ -139,7 +139,7 @@ typedef struct string_list { char string[1]; } ATTR_PACKED(void *) string_list_t; -void add_string_list_n( string_list_t **list, const char *str, int len ); +void add_string_list_n( string_list_t **list, const char *str, uint len ); void add_string_list( string_list_t **list, const char *str ); void free_string_list( string_list_t *list ); @@ -150,9 +150,9 @@ void *memrchr( const void *s, int c, size_t n ); size_t strnlen( const char *str, size_t maxlen ); #endif -int starts_with( const char *str, int strl, const char *cmp, int cmpl ); -int starts_with_upper( const char *str, int strl, const char *cmp, int cmpl ); -int equals( const char *str, int strl, const char *cmp, int cmpl ); +int starts_with( const char *str, int strl, const char *cmp, uint cmpl ); +int starts_with_upper( const char *str, int strl, const char *cmp, uint cmpl ); +int equals( const char *str, int strl, const char *cmp, uint cmpl ); #ifndef HAVE_TIMEGM time_t timegm( struct tm *tm ); @@ -170,16 +170,16 @@ void ATTR_NORETURN oob( void ); char *expand_strdup( const char *s ); -int map_name( const char *arg, char **result, int reserve, const char *in, const char *out ); +int map_name( const char *arg, char **result, uint reserve, const char *in, const char *out ); #define DEFINE_ARRAY_TYPE(T) \ typedef struct { \ T *data; \ - int size; \ + uint size; \ } ATTR_PACKED(T *) T##_array_t; \ typedef struct { \ T##_array_t array; \ - int alloc; \ + uint alloc; \ } ATTR_PACKED(T *) T##_array_alloc_t; \ static INLINE T *T##_array_append( T##_array_alloc_t *arr ) \ { \ @@ -205,7 +205,7 @@ int find_uint_array( const uint_array_t array, uint value ); void arc4_init( void ); uchar arc4_getbyte( void ); -int bucketsForSize( int size ); +uint bucketsForSize( uint size ); typedef struct list_head { struct list_head *next, *prev; @@ -216,7 +216,7 @@ typedef struct notifier { void (*cb)( int what, void *aux ); void *aux; #ifdef HAVE_SYS_POLL_H - int index; + uint index; #else int fd; short events; diff --git a/src/config.c b/src/config.c @@ -121,13 +121,13 @@ parse_int( conffile_t *cfile ) return ret; } -int +uint parse_size( conffile_t *cfile ) { char *p; - int ret; + uint ret; - ret = strtol (cfile->val, &p, 10); + ret = strtoul( cfile->val, &p, 10 ); if (*p == 'k' || *p == 'K') ret *= 1024, p++; else if (*p == 'm' || *p == 'M') @@ -319,7 +319,8 @@ load_config( const char *where, int pseudo ) group_conf_t *group, **groupapp = &groups; string_list_t *chanlist, **chanlistapp; char *arg, *p; - int len, cops, gcops, max_size, ms, i; + uint len, max_size; + int cops, gcops, ms, i; char path[_POSIX_PATH_MAX]; char buf[1024]; @@ -354,7 +355,7 @@ load_config( const char *where, int pseudo ) if (drivers[i]->parse_store( &cfile, &store )) { if (store) { if (!store->max_size) - store->max_size = INT_MAX; + store->max_size = UINT_MAX; if (!store->flat_delim) store->flat_delim = ""; *storeapp = store; @@ -371,7 +372,7 @@ load_config( const char *where, int pseudo ) channel->expire_unread = global_conf.expire_unread; channel->use_internal_date = global_conf.use_internal_date; cops = 0; - max_size = -1; + max_size = UINT_MAX; while (getcline( &cfile ) && cfile.cmd) { if (!strcasecmp( "MaxSize", cfile.cmd )) max_size = parse_size( &cfile ); @@ -422,9 +423,9 @@ load_config( const char *where, int pseudo ) } else if (merge_ops( cops, channel->ops )) cfile.err = 1; else { - if (max_size >= 0) { + if (max_size != UINT_MAX) { if (!max_size) - max_size = INT_MAX; + max_size = UINT_MAX; channel->stores[M]->max_size = channel->stores[S]->max_size = max_size; } *channelapp = channel; @@ -487,8 +488,8 @@ load_config( const char *where, int pseudo ) else if (!strcasecmp( "BufferLimit", cfile.cmd )) { BufferLimit = parse_size( &cfile ); - if (BufferLimit <= 0) { - error( "%s:%d: BufferLimit must be positive\n", cfile.file, cfile.line ); + if (!BufferLimit) { + error( "%s:%d: BufferLimit cannot be zero\n", cfile.file, cfile.line ); cfile.err = 1; } } diff --git a/src/config.h b/src/config.h @@ -42,7 +42,7 @@ char *get_arg( conffile_t *cfile, int required, int *comment ); char parse_bool( conffile_t *cfile ); int parse_int( conffile_t *cfile ); -int parse_size( conffile_t *cfile ); +uint parse_size( conffile_t *cfile ); int getcline( conffile_t *cfile ); int merge_ops( int cops, int ops[] ); int load_config( const char *filename, int pseudo ); diff --git a/src/driver.c b/src/driver.c @@ -27,10 +27,10 @@ driver_t *drivers[N_DRIVERS] = { &maildir_driver, &imap_driver }; -int +uint count_generic_messages( message_t *msgs ) { - int count = 0; + uint count = 0; for (; msgs; msgs = msgs->next) count++; return count; diff --git a/src/driver.h b/src/driver.h @@ -39,7 +39,7 @@ typedef struct store_conf { const char *flat_delim; const char *map_inbox; const char *trash; - int max_size; /* off_t is overkill */ + uint max_size; /* off_t is overkill */ char trash_remote_new, trash_only_new; } store_conf_t; @@ -67,7 +67,7 @@ typedef struct message { struct sync_rec *srec; char *msgid; /* owned */ /* string_list_t *keywords; */ - int size; /* zero implies "not fetched" */ + uint size; /* zero implies "not fetched" */ uint uid; uchar flags, status; char tuid[TUIDL]; @@ -95,7 +95,7 @@ typedef struct store { typedef struct { char *data; - int len; + uint len; time_t date; uchar flags; } msg_data_t; @@ -127,7 +127,7 @@ typedef struct { #define LIST_PATH 2 #define LIST_PATH_MAYBE 4 -#define xint int // For auto-generation of appropriate printf() formats. +#define xint uint // For auto-generation of appropriate printf() formats. struct driver { /* Return driver capabilities. */ @@ -258,13 +258,13 @@ struct driver { void (*commit_cmds)( store_t *ctx ); /* Get approximate amount of memory occupied by the driver. */ - int (*get_memory_usage)( store_t *ctx ); + uint (*get_memory_usage)( store_t *ctx ); /* Get the FAIL_* state of the driver. */ int (*get_fail_state)( store_conf_t *conf ); }; -int count_generic_messages( message_t * ); +uint count_generic_messages( message_t * ); void free_generic_messages( message_t * ); void parse_generic_store( store_conf_t *store, conffile_t *cfg ); diff --git a/src/drv_imap.c b/src/drv_imap.c @@ -53,7 +53,7 @@ typedef struct imap_server_conf { char *pass; char *pass_cmd; int max_in_progress; - int cap_mask; + uint cap_mask; string_list_t *auth_mechs; #ifdef HAVE_LIBSSL char ssl_type; @@ -71,7 +71,7 @@ typedef struct { typedef struct { message_t gen; -/* int seq; will be needed when expunges are tracked */ +/* uint seq; will be needed when expunges are tracked */ } imap_message_t; #define NIL (void*)0x1 @@ -80,7 +80,7 @@ typedef struct { typedef struct _list { struct _list *next, *child; char *val; - int len; + uint len; } list_t; #define MAX_LIST_DEPTH 5 @@ -100,7 +100,7 @@ struct imap_store { const char *label; /* foreign */ const char *prefix; const char *name; - int ref_count; + uint ref_count; uint opts; enum { SST_BAD, SST_HALF, SST_GOOD } state; /* trash folder's existence is not confirmed yet */ @@ -124,7 +124,7 @@ struct imap_store { int nexttag, num_in_progress; imap_cmd_t *pending, **pending_append; imap_cmd_t *in_progress, **in_progress_append; - int buffer_mem; /* memory currently occupied by buffers in the queue */ + uint buffer_mem; /* memory currently occupied by buffers in the queue */ /* Used during sequential operations like connect */ enum { GreetingPending = 0, GreetingBad, GreetingOk, GreetingPreauth } greeting; @@ -158,7 +158,7 @@ struct imap_cmd { int (*cont)( imap_store_t *ctx, imap_cmd_t *cmd, const char *prompt ); void (*done)( imap_store_t *ctx, imap_cmd_t *cmd, int response ); char *data; - int data_len; + uint data_len; uint uid; /* to identify fetch responses */ char high_prio; /* if command is queued, put it at the front of the queue. */ char to_trash; /* we are storing to trash, not current. */ @@ -195,7 +195,7 @@ typedef struct { } imap_cmd_find_new_t; typedef struct { - int ref_count; + uint ref_count; int ret_val; } imap_cmd_refcounted_state_t; @@ -258,7 +258,7 @@ static const char *Flags[] = { }; static imap_cmd_t * -new_imap_cmd( int size ) +new_imap_cmd( uint size ) { imap_cmd_t *cmd = nfmalloc( size ); memset( &cmd->param, 0, sizeof(cmd->param) ); @@ -290,7 +290,8 @@ done_imap_cmd( imap_store_t *ctx, imap_cmd_t *cmd, int response ) static void send_imap_cmd( imap_store_t *ctx, imap_cmd_t *cmd ) { - int bufl, litplus, iovcnt = 1; + int litplus, iovcnt = 1; + int bufl; const char *buffmt; conn_iovec_t iov[3]; char buf[4096]; @@ -323,7 +324,7 @@ DIAG_POP fflush( stdout ); } iov[0].buf = buf; - iov[0].len = bufl; + iov[0].len = (uint)bufl; iov[0].takeOwn = KeepOwn; if (litplus) { if (DFlags & DEBUG_NET_ALL) { @@ -451,7 +452,6 @@ imap_vprintf( const char *fmt, va_list ap ) { const char *s; char *d, *ed; - int maxlen; char c; char buf[4096]; @@ -461,14 +461,14 @@ imap_vprintf( const char *fmt, va_list ap ) for (;;) { c = *fmt; if (!c || c == '%') { - int l = fmt - s; + uint l = fmt - s; if (d + l > ed) oob(); memcpy( d, s, l ); d += l; if (!c) - return nfstrndup( buf, d - buf ); - maxlen = INT_MAX; + return nfstrndup( buf, (size_t)(d - buf) ); + uint maxlen = UINT_MAX; c = *++fmt; if (c == '\\') { c = *++fmt; @@ -491,7 +491,7 @@ imap_vprintf( const char *fmt, va_list ap ) fputs( "Fatal: unsupported string length specification. Please report a bug.\n", stderr ); abort(); } - maxlen = va_arg( ap , int ); + maxlen = va_arg( ap, uint ); c = *++fmt; } if (c == 'c') { @@ -578,7 +578,7 @@ imap_done_simple_msg( imap_store_t *ctx ATTR_UNUSED, } static imap_cmd_refcounted_state_t * -imap_refcounted_new_state( int sz ) +imap_refcounted_new_state( uint sz ) { imap_cmd_refcounted_state_t *sts = nfmalloc( sz ); sts->ref_count = 1; /* so forced sync does not cause an early exit */ @@ -787,7 +787,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts ) goto next2; } else if (ctx && *s == '{') { /* literal */ - bytes = cur->len = strtol( s + 1, &s, 10 ); + bytes = (int)(cur->len = strtoul( s + 1, &s, 10 )); if (*s != '}' || *++s) goto bail; @@ -795,7 +795,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts ) s[cur->len] = 0; getbytes: - n = socket_read( &ctx->conn, s, bytes ); + n = socket_read( &ctx->conn, s, (uint)bytes ); if (n < 0) { badeof: error( "IMAP error: unexpected EOF from %s\n", ctx->conn.name ); @@ -832,7 +832,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts ) goto bail; *d++ = c; } - cur->len = d - p; + cur->len = (uint)(d - p); cur->val = nfstrndup( p, cur->len ); } else { /* atom */ @@ -840,8 +840,8 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts ) for (; *s && !isspace( (uchar)*s ); s++) if (sts->level && *s == ')') break; - cur->len = s - p; - if (equals( p, cur->len, "NIL", 3 )) + cur->len = (uint)(s - p); + if (equals( p, (int)cur->len, "NIL", 3 )) cur->val = NIL; else cur->val = nfstrndup( p, cur->len ); @@ -975,8 +975,8 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED ) imap_message_t *cur; msg_data_t *msgdata; imap_cmd_t *cmdp; - int mask = 0, status = 0, size = 0; - uint i, uid = 0; + uchar mask = 0, status = 0; + uint i, uid = 0, size = 0; time_t date = 0; if (!is_list( list )) { @@ -1080,7 +1080,7 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED ) in_msgid = 1; continue; } - msgid = nfstrndup( val + off, len - off ); + msgid = nfstrndup( val + off, (size_t)(len - off) ); in_msgid = 0; } } else { @@ -1291,7 +1291,8 @@ parse_list_rsp_p2( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED ) { string_list_t *narg; char *arg; - int argl, l; + int argl; + uint l; if (!is_atom( list )) { error( "IMAP error: malformed LIST response\n" ); @@ -1299,7 +1300,7 @@ parse_list_rsp_p2( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED ) return LIST_BAD; } arg = list->val; - argl = list->len; + argl = (int)list->len; if (is_inbox( ctx, arg, argl )) { // The server might be weird and have a non-uppercase INBOX. It // may legitimately do so, but we need the canonical spelling. @@ -1335,7 +1336,7 @@ parse_list_rsp_p2( imap_store_t *ctx, list_t *list, char *cmd ATTR_UNUSED ) static int prepare_name( char **buf, const imap_store_t *ctx, const char *prefix, const char *name ) { - int pl = strlen( prefix ); + uint pl = strlen( prefix ); switch (map_name( name, buf, pl, "/", ctx->delimiter )) { case -1: @@ -2172,7 +2173,7 @@ imap_open_store_authenticate2( imap_store_t *ctx ) skipped_login = 1; #ifdef HAVE_LIBSASL } else { - int len = strlen( cmech->string ); + uint len = strlen( cmech->string ); if (saslend + len + 2 > saslmechs + sizeof(saslmechs)) oob(); *saslend++ = ' '; @@ -2567,8 +2568,8 @@ imap_finish_delete_box( store_t *gctx ATTR_UNUSED ) /******************* imap_load_box *******************/ -static int -imap_prepare_load_box( store_t *gctx, int opts ) +static uint +imap_prepare_load_box( store_t *gctx, uint opts ) { imap_store_t *ctx = (imap_store_t *)gctx; @@ -2578,14 +2579,15 @@ imap_prepare_load_box( store_t *gctx, int opts ) enum { WantSize = 1, WantTuids = 2, WantMsgids = 4 }; typedef struct { - int first, last, flags; + uint first, last; + int flags; } imap_range_t; static void -imap_set_range( imap_range_t *ranges, int *nranges, int low_flags, int high_flags, int maxlow ) +imap_set_range( imap_range_t *ranges, uint *nranges, int low_flags, int high_flags, uint maxlow ) { if (low_flags != high_flags) { - for (int r = 0; r < *nranges; r++) { + for (uint r = 0; r < *nranges; r++) { if (ranges[r].first > maxlow) break; /* Range starts above split point; so do all subsequent ranges. */ if (ranges[r].last < maxlow) @@ -2599,7 +2601,7 @@ imap_set_range( imap_range_t *ranges, int *nranges, int low_flags, int high_flag break; } } - for (int r = 0; r < *nranges; r++) + for (uint r = 0; r < *nranges; r++) ranges[r].flags |= (ranges[r].last <= maxlow) ? low_flags : high_flags; } @@ -2617,7 +2619,6 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint seenui void (*cb)( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux ), void *aux ) { imap_store_t *ctx = (imap_store_t *)gctx; - int i, j, bl; char buf[1000]; if (!ctx->total_msgs) { @@ -2625,12 +2626,12 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint seenui cb( DRV_OK, 0, 0, 0, aux ); } else { INIT_REFCOUNTED_STATE(imap_load_box_state_t, sts, cb, aux) - for (i = 0; i < excs.size; ) { - for (bl = 0; i < excs.size && bl < 960; i++) { + for (uint i = 0; i < excs.size; ) { + for (int bl = 0; i < excs.size && bl < 960; i++) { if (bl) buf[bl++] = ','; bl += sprintf( buf + bl, "%u", excs.data[i] ); - j = i; + uint j = i; for (; i + 1 < excs.size && excs.data[i + 1] == excs.data[i] + 1; i++) {} if (i != j) bl += sprintf( buf + bl, ":%u", excs.data[i] ); @@ -2644,7 +2645,7 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint seenui ranges[0].first = minuid; ranges[0].last = maxuid; ranges[0].flags = 0; - int nranges = 1; + uint nranges = 1; if (ctx->opts & (OPEN_OLD_SIZE | OPEN_NEW_SIZE)) imap_set_range( ranges, &nranges, shifted_bit( ctx->opts, OPEN_OLD_SIZE, WantSize), shifted_bit( ctx->opts, OPEN_NEW_SIZE, WantSize), seenuid ); @@ -2652,7 +2653,7 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint seenui imap_set_range( ranges, &nranges, 0, WantTuids, newuid - 1 ); if (ctx->opts & OPEN_OLD_IDS) imap_set_range( ranges, &nranges, WantMsgids, 0, seenuid ); - for (int r = 0; r < nranges; r++) { + for (uint r = 0; r < nranges; r++) { sprintf( buf, "%u:%u", ranges[r].first, ranges[r].last ); imap_submit_load( ctx, buf, ranges[r].flags, sts ); } @@ -2678,14 +2679,14 @@ imap_sort_msgs_comp( const void *a_, const void *b_ ) static void imap_sort_msgs( imap_store_t *ctx ) { - int count = count_generic_messages( ctx->msgs ); + uint count = count_generic_messages( ctx->msgs ); if (count <= 1) return; message_t **t = nfmalloc( sizeof(*t) * count ); message_t *m = ctx->msgs; - for (int i = 0; i < count; i++) { + for (uint i = 0; i < count; i++) { t[i] = m; m = m->next; } @@ -2694,7 +2695,7 @@ imap_sort_msgs( imap_store_t *ctx ) ctx->msgs = t[0]; - int j; + uint j; for (j = 0; j < count - 1; j++) t[j]->next = t[j + 1]; ctx->msgapp = &t[j]->next; @@ -2771,7 +2772,7 @@ imap_fetch_msg_p2( imap_store_t *ctx, imap_cmd_t *gcmd, int response ) /******************* imap_set_msg_flags *******************/ -static int +static uint imap_make_flags( int flags, char *buf ) { const char *s; @@ -2946,7 +2947,7 @@ imap_store_msg( store_t *gctx, msg_data_t *data, int to_trash, imap_store_t *ctx = (imap_store_t *)gctx; imap_cmd_out_uid_t *cmd; char *buf; - int d; + uint d; char flagstr[128], datestr[64]; d = 0; @@ -3166,7 +3167,7 @@ imap_commit_cmds( store_t *gctx ) /******************* imap_get_memory_usage *******************/ -static int +static uint imap_get_memory_usage( store_t *gctx ) { imap_store_t *ctx = (imap_store_t *)gctx; @@ -3485,7 +3486,7 @@ imap_parse_store( conffile_t *cfg, store_conf_t **storep ) return 1; } -static int +static uint imap_get_caps( store_t *gctx ATTR_UNUSED ) { return DRV_CRLF | DRV_VERBOSE; diff --git a/src/drv_maildir.c b/src/drv_maildir.c @@ -69,9 +69,8 @@ typedef struct { typedef struct { store_t gen; - uint opts; int uvfd, uvok, is_inbox, fresh[3]; - uint minuid, maxuid, newuid, seenuid, uidvalidity, nuid; + uint opts, minuid, maxuid, newuid, seenuid, uidvalidity, nuid; uint_array_t excs; char *path; /* own */ char *trash; @@ -146,7 +145,7 @@ maildir_join_path( maildir_store_conf_t *conf, int in_inbox, const char *box ) { char *out, *p; const char *prefix; - int pl, bl, n; + uint pl, bl, n; char c; if (in_inbox || conf->sub_style == SUB_MAILDIRPP) { @@ -389,7 +388,7 @@ static int maildir_list_path( maildir_store_t *ctx, int flags, const char *inbox static int maildir_list_recurse( maildir_store_t *ctx, int isBox, int flags, - const char *inbox, int inboxLen, const char *basePath, int basePathLen, + const char *inbox, uint inboxLen, const char *basePath, uint basePathLen, char *path, int pathLen, char *name, int nameLen ) { DIR *dir; @@ -525,7 +524,7 @@ static const char *subdirs[] = { "cur", "new", "tmp" }; typedef struct { char *base; char *msgid; - int size; + uint size; uint uid; uchar recent; char tuid[TUIDL]; @@ -536,7 +535,7 @@ DEFINE_ARRAY_TYPE(msg_t) static void maildir_free_scan( msg_t_array_alloc_t *msglist ) { - int i; + uint i; if (msglist->array.data) { for (i = 0; i < msglist->array.size; i++) @@ -587,7 +586,7 @@ make_box_dir( char *buf, int bl ) if (!mkdir( buf, 0700 ) || errno == EEXIST) return 0; - p = memrchr( buf, '/', bl - 1 ); + p = memrchr( buf, '/', (size_t)bl - 1 ); *p = 0; if (make_box_dir( buf, (int)(p - buf) )) return -1; @@ -688,7 +687,7 @@ maildir_store_uidval( maildir_store_t *ctx ) { n = sprintf( buf, "%u\n%u\n", ctx->uidvalidity, ctx->nuid ); lseek( ctx->uvfd, 0, SEEK_SET ); - if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n ) || (UseFSync && fdatasync( ctx->uvfd ))) { + if (write( ctx->uvfd, buf, (uint)n ) != n || ftruncate( ctx->uvfd, n ) || (UseFSync && fdatasync( ctx->uvfd ))) { error( "Maildir error: cannot write UIDVALIDITY.\n" ); return DRV_BOX_BAD; } @@ -849,7 +848,8 @@ maildir_compare( const void *l, const void *r ) { const msg_t *lm = (const msg_t *)l, *rm = (const msg_t *)r; char *ldot, *rdot, *ldot2, *rdot2, *lseq, *rseq; - int ret, llen, rlen; + uint llen, rlen; + int ret; if (lm->uid != rm->uid) // Can't subtract, the result might not fit into signed int. return lm->uid > rm->uid ? 1 : -1; @@ -860,21 +860,21 @@ maildir_compare( const void *l, const void *r ) faster than numeric. */ if (!(ldot = strchr( lm->base, '.' )) || !(rdot = strchr( rm->base, '.' ))) goto stronly; /* Should never happen ... */ - llen = ldot - lm->base, rlen = rdot - rm->base; + llen = (uint)(ldot - lm->base), rlen = (uint)(rdot - rm->base); /* The shorter number is smaller. Really. This won't trigger with any mail created after Sep 9 2001 anyway. */ - if ((ret = llen - rlen)) + if ((ret = (int)llen - (int)rlen)) return ret; if ((ret = memcmp( lm->base, rm->base, llen ))) return ret; ldot++, rdot++; - if ((llen = strtol( ldot, &ldot2, 10 ))) { - if (!(rlen = strtol( rdot, &rdot2, 10 ))) + if ((llen = strtoul( ldot, &ldot2, 10 ))) { + if (!(rlen = strtoul( rdot, &rdot2, 10 ))) goto stronly; /* Comparing apples to oranges ... */ /* Classical PID specs */ - if ((ret = llen - rlen)) { + if ((ret = (int)llen - (int)rlen)) { retpid: /* Handle PID wraparound. This works only on systems where PIDs are not reused too fast */ @@ -888,7 +888,7 @@ maildir_compare( const void *l, const void *r ) if (!(ldot2 = strchr( ldot, '.' )) || !(rdot2 = strchr( rdot, '.' ))) goto stronly; /* Should never happen ... */ - llen = ldot2 - ldot, rlen = rdot2 - rdot; + llen = (uint)(ldot2 - ldot), rlen = (uint)(rdot2 - rdot); if (((lseq = memchr( ldot, '#', llen )) && (rseq = memchr( rdot, '#', rlen ))) || ((lseq = memchr( ldot, 'M', llen )) && (rseq = memchr( rdot, 'M', rlen )))) @@ -919,7 +919,8 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) DBC *dbc; #endif /* USE_DB */ msg_t *entry; - int i, bl, fnl, ret; + uint i; + int bl, fnl, ret; uint uid; time_t now, stamps[2]; struct stat st; @@ -1053,7 +1054,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) ctx->db->err( ctx->db, ret, "Maildir error: db->c_get()" ); break; } - if (!equals( key.data, key.size, "UIDVALIDITY", 11 ) && + if (!equals( key.data, (int)key.size, "UIDVALIDITY", 11 ) && (ret = tdb->get( tdb, 0, &key, &value, 0 ))) { if (ret != DB_NOTFOUND) { tdb->err( tdb, ret, "Maildir error: tdb->get()" ); @@ -1119,11 +1120,11 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) else u = ru = strchr( entry->base, conf->info_delimiter ); fnl = (u ? - nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%.*s,U=%u%s", subdirs[entry->recent], (int)(u - entry->base), entry->base, uid, ru ) : - nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%s,U=%u", subdirs[entry->recent], entry->base, uid )) + nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, "%s/%.*s,U=%u%s", subdirs[entry->recent], (int)(u - entry->base), entry->base, uid, ru ) : + nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, "%s/%s,U=%u", subdirs[entry->recent], entry->base, uid )) - 4; - memcpy( nbuf, buf, bl + 4 ); - nfsnprintf( nbuf + bl + 4, sizeof(nbuf) - bl - 4, "%s", entry->base ); + memcpy( nbuf, buf, (size_t)(bl + 4) ); + nfsnprintf( nbuf + bl + 4, _POSIX_PATH_MAX - bl - 4, "%s", entry->base ); if (rename( nbuf, buf )) { if (errno != ENOENT) { sys_error( "Maildir error: cannot rename %s to %s", nbuf, buf ); @@ -1136,7 +1137,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) goto again; } free( entry->base ); - entry->base = nfstrndup( buf + bl + 4, fnl ); + entry->base = nfstrndup( buf + bl + 4, (size_t)fnl ); } int want_size = (uid > ctx->seenuid) ? (ctx->opts & OPEN_NEW_SIZE) : (ctx->opts & OPEN_OLD_SIZE); int want_tuid = ((ctx->opts & OPEN_FIND) && uid >= ctx->newuid); @@ -1144,7 +1145,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) if (!want_size && !want_tuid && !want_msgid) continue; if (!fnl) - nfsnprintf( buf + bl, sizeof(buf) - bl, "%s/%s", subdirs[entry->recent], entry->base ); + nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, "%s/%s", subdirs[entry->recent], entry->base ); if (want_size) { if (stat( buf, &st )) { if (errno != ENOENT) { @@ -1153,7 +1154,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) } goto retry; } - entry->size = st.st_size; + entry->size = (uint)st.st_size; } if (want_tuid || want_msgid) { if (!(f = fopen( buf, "r" ))) { @@ -1200,7 +1201,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) in_msgid = 1; continue; } - entry->msgid = nfstrndup( lnbuf + off, bufl - off ); + entry->msgid = nfstrndup( lnbuf + off, (size_t)(bufl - off) ); want_msgid = 0; in_msgid = 0; } @@ -1383,11 +1384,11 @@ maildir_delete_box( store_t *gctx, error( "Maildir error: '%s' is no valid mailbox\n", ctx->path ); ret = DRV_BOX_BAD; } else if ((ret = maildir_clear_tmp( buf, sizeof(buf), bl )) == DRV_OK) { - nfsnprintf( buf + bl, sizeof(buf) - bl, ".uidvalidity" ); + nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, ".uidvalidity" ); if (unlink( buf ) && errno != ENOENT) goto badrm; #ifdef USE_DB - nfsnprintf( buf + bl, sizeof(buf) - bl, ".isyncuidmap.db" ); + nfsnprintf( buf + bl, _POSIX_PATH_MAX - bl, ".isyncuidmap.db" ); if (unlink( buf ) && errno != ENOENT) goto badrm; #endif @@ -1420,8 +1421,8 @@ maildir_finish_delete_box( store_t *gctx ) return DRV_OK; } -static int -maildir_prepare_load_box( store_t *gctx, int opts ) +static uint +maildir_prepare_load_box( store_t *gctx, uint opts ) { maildir_store_t *ctx = (maildir_store_t *)gctx; @@ -1440,7 +1441,7 @@ maildir_load_box( store_t *gctx, uint minuid, uint maxuid, uint newuid, uint see maildir_store_t *ctx = (maildir_store_t *)gctx; message_t **msgapp; msg_t_array_alloc_t msglist; - int i; + uint i; ctx->minuid = minuid; ctx->maxuid = maxuid; @@ -1467,7 +1468,7 @@ maildir_rescan( maildir_store_t *ctx ) message_t **msgapp; maildir_message_t *msg; msg_t_array_alloc_t msglist; - int i; + uint i; ctx->fresh[0] = ctx->fresh[1] = 0; if (maildir_scan( ctx, &msglist ) != DRV_OK) @@ -1567,14 +1568,14 @@ maildir_fetch_msg( store_t *gctx, message_t *gmsg, msg_data_t *data, } static int -maildir_make_flags( char info_delimiter, int flags, char *buf ) +maildir_make_flags( char info_delimiter, uchar flags, char *buf ) { - uint i, d; + int i, d; buf[0] = info_delimiter; buf[1] = '2'; buf[2] = ','; - for (d = 3, i = 0; i < as(Flags); i++) + for (d = 3, i = 0; i < (int)as(Flags); i++) if (flags & (1 << i)) buf[d++] = Flags[i]; buf[d] = 0; @@ -1608,7 +1609,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash, cb( ret, 0, aux ); return; } - nfsnprintf( base + bl, sizeof(base) - bl, ",U=%u", uid ); + nfsnprintf( base + bl, (int)sizeof(base) - bl, ",U=%u", uid ); } box = ctx->path; } else { @@ -1639,7 +1640,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash, } ret = write( fd, data->data, data->len ); free( data->data ); - if (ret != data->len || (UseFSync && (ret = fsync( fd )))) { + if (ret != (int)data->len || (UseFSync && (ret = fsync( fd )))) { if (ret < 0) sys_error( "Maildir error: cannot write %s", buf ); else @@ -1689,28 +1690,28 @@ maildir_set_msg_flags( store_t *gctx, message_t *gmsg, uint uid ATTR_UNUSED, int char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX]; bbl = nfsnprintf( buf, sizeof(buf), "%s/", ctx->path ); - memcpy( nbuf, ctx->path, bbl - 1 ); + memcpy( nbuf, ctx->path, (size_t)bbl - 1 ); memcpy( nbuf + bbl - 1, "/cur/", 5 ); for (;;) { - bl = bbl + nfsnprintf( buf + bbl, sizeof(buf) - bbl, "%s/", subdirs[gmsg->status & M_RECENT] ); + bl = bbl + nfsnprintf( buf + bbl, _POSIX_PATH_MAX - bbl, "%s/", subdirs[gmsg->status & M_RECENT] ); ol = strlen( msg->base ); - if ((int)sizeof(buf) - bl < ol + 3 + NUM_FLAGS) + if (_POSIX_PATH_MAX - bl < ol + 3 + NUM_FLAGS) oob(); - memcpy( buf + bl, msg->base, ol + 1 ); - memcpy( nbuf + bl, msg->base, ol + 1 ); + memcpy( buf + bl, msg->base, (size_t)ol + 1 ); + memcpy( nbuf + bl, msg->base, (size_t)ol + 1 ); if ((s = strstr( nbuf + bl, conf->info_prefix ))) { s += 3; fl = ol - (s - (nbuf + bl)); for (i = 0; i < as(Flags); i++) { if ((p = strchr( s, Flags[i] ))) { if (del & (1 << i)) { - memmove( p, p + 1, fl - (p - s) ); + memmove( p, p + 1, (size_t)fl - (size_t)(p - s) ); fl--; } } else if (add & (1 << i)) { for (j = 0; j < fl && Flags[i] > s[j]; j++); fl++; - memmove( s + j + 1, s + j, fl - j ); + memmove( s + j + 1, s + j, (size_t)(fl - j) ); s[j] = Flags[i]; } } @@ -1726,7 +1727,7 @@ maildir_set_msg_flags( store_t *gctx, message_t *gmsg, uint uid ATTR_UNUSED, int } } free( msg->base ); - msg->base = nfstrndup( nbuf + bl, tl ); + msg->base = nfstrndup( nbuf + bl, (size_t)tl ); msg->gen.flags |= add; msg->gen.flags &= ~del; gmsg->status &= ~M_RECENT; @@ -1813,7 +1814,7 @@ maildir_close_box( store_t *gctx, basel = nfsnprintf( buf, sizeof(buf), "%s/", ctx->path ); for (msg = ctx->msgs; msg; msg = msg->next) if (!(msg->status & M_DEAD) && (msg->flags & F_DELETED)) { - nfsnprintf( buf + basel, sizeof(buf) - basel, "%s/%s", subdirs[msg->status & M_RECENT], ((maildir_message_t *)msg)->base ); + nfsnprintf( buf + basel, _POSIX_PATH_MAX - basel, "%s/%s", subdirs[msg->status & M_RECENT], ((maildir_message_t *)msg)->base ); if (unlink( buf )) { if (errno == ENOENT) retry = 1; @@ -1854,7 +1855,7 @@ maildir_commit_cmds( store_t *gctx ) (void) gctx; } -static int +static uint maildir_get_memory_usage( store_t *gctx ATTR_UNUSED ) { return 0; @@ -1924,7 +1925,7 @@ maildir_parse_store( conffile_t *cfg, store_conf_t **storep ) return 1; } -static int +static uint maildir_get_caps( store_t *gctx ATTR_UNUSED ) { return 0; /* XXX DRV_CRLF? */ diff --git a/src/drv_proxy.c b/src/drv_proxy.c @@ -27,7 +27,7 @@ typedef struct { store_t gen; const char *label; // foreign - int ref_count; + uint ref_count; driver_t *real_driver; store_t *real_store; @@ -61,7 +61,7 @@ debugn( const char *msg, ... ) static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' }; static char * -proxy_make_flags( int flags, char *buf ) +proxy_make_flags( uchar flags, char *buf ) { uint i, d; @@ -82,13 +82,13 @@ proxy_store_deref( proxy_store_t *ctx ) static int curr_tag; typedef struct { - int ref_count; + uint ref_count; int tag; proxy_store_t *ctx; } gen_cmd_t; static gen_cmd_t * -proxy_cmd_new( proxy_store_t *ctx, int sz ) +proxy_cmd_new( proxy_store_t *ctx, uint sz ) { gen_cmd_t *cmd = nfmalloc( sz ); cmd->ref_count = 2; @@ -203,7 +203,7 @@ proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), v //# DEFINE load_box_print_args if (excs.size) { debugn( " excs:" ); - for (int t = 0; t < excs.size; t++) + for (uint t = 0; t < excs.size; t++) debugn( " %u", excs.data[t] ); debug( "\n" ); } @@ -216,7 +216,7 @@ proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), v //# DEFINE load_box_print_cb_args if (sts == DRV_OK) { for (message_t *msg = msgs; msg; msg = msg->next) - debug( " uid=%-5u flags=%-4s size=%-6d tuid=%." stringify(TUIDL) "s\n", + debug( " uid=%-5u flags=%-4s size=%-6u tuid=%." stringify(TUIDL) "s\n", msg->uid, (msg->status & M_FLAGS) ? (proxy_make_flags( msg->flags, fbuf ), fbuf) : "?", msg->size, *msg->tuid ? msg->tuid : "?" ); } //# END @@ -242,7 +242,7 @@ proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), v static char fbuf[as(Flags) + 1]; proxy_make_flags( cmd->data->flags, fbuf ); //# END -//# DEFINE fetch_msg_print_fmt_cb_args , flags=%s, date=%lld, size=%d +//# DEFINE fetch_msg_print_fmt_cb_args , flags=%s, date=%lld, size=%u //# DEFINE fetch_msg_print_pass_cb_args , fbuf, (long long)cmd->data->date, cmd->data->len //# DEFINE fetch_msg_print_cb_args if (sts == DRV_OK && (DFlags & DEBUG_DRV_ALL)) { @@ -257,7 +257,7 @@ proxy_@name@( store_t *gctx@decl_args@, void (*cb)( @decl_cb_args@void *aux ), v static char fbuf[as(Flags) + 1]; proxy_make_flags( data->flags, fbuf ); //# END -//# DEFINE store_msg_print_fmt_args , flags=%s, date=%lld, size=%d, to_trash=%s +//# DEFINE store_msg_print_fmt_args , flags=%s, date=%lld, size=%u, to_trash=%s //# DEFINE store_msg_print_pass_args , fbuf, (long long)data->date, data->len, to_trash ? "yes" : "no" //# DEFINE store_msg_print_args if (DFlags & DEBUG_DRV_ALL) { diff --git a/src/main.c b/src/main.c @@ -47,7 +47,7 @@ int Pid; /* for maildir and imap */ char Hostname[256]; /* for maildir */ const char *Home; /* for config */ -int BufferLimit = 10 * 1024 * 1024; +uint BufferLimit = 10 * 1024 * 1024; static int chans_total, chans_done; static int boxes_total, boxes_done; @@ -264,7 +264,7 @@ filter_boxes( string_list_t *boxes, const char *prefix, string_list_t *patterns string_list_t *cpat; char **boxarr = 0; const char *ps; - int not, fnot, pfxl, num = 0, rnum = 0; + uint not, fnot, pfxl, num = 0, rnum = 0; pfxl = prefix ? strlen( prefix ) : 0; for (; boxes; boxes = boxes->next) { @@ -350,7 +350,8 @@ add_named_channel( chan_ent_t ***chanapp, char *channame, int ops[] ) chan_ent_t *ce; box_ent_t *boxes = 0, **mboxapp = &boxes, *mbox; char *boxp, *nboxp; - int boxl, boxlist = 0; + size_t boxl; + char boxlist = 0; if ((boxp = strchr( channame, ':' ))) *boxp++ = 0; @@ -369,7 +370,7 @@ add_named_channel( chan_ent_t ***chanapp, char *channame, int ops[] ) do { nboxp = strpbrk( boxp, ",\n" ); if (nboxp) { - boxl = nboxp - boxp; + boxl = (size_t)(nboxp - boxp); *nboxp++ = 0; } else { boxl = strlen( boxp ); diff --git a/src/socket.c b/src/socket.c @@ -250,7 +250,7 @@ DIAG_POP return 0; } - int options = SSL_OP_NO_SSLv3; + uint options = SSL_OP_NO_SSLv3; if (!(conf->ssl_versions & TLSv1)) options |= SSL_OP_NO_TLSv1; #ifdef SSL_OP_NO_TLSv1_1 @@ -678,9 +678,9 @@ socket_close( conn_t *sock ) } static int -prepare_read( conn_t *sock, char **buf, int *len ) +prepare_read( conn_t *sock, char **buf, uint *len ) { - int n = sock->offset + sock->bytes; + uint n = sock->offset + sock->bytes; if (!(*len = sizeof(sock->buf) - n)) { error( "Socket error: receive buffer full. Probably protocol error.\n" ); socket_fail( sock ); @@ -691,17 +691,17 @@ prepare_read( conn_t *sock, char **buf, int *len ) } static int -do_read( conn_t *sock, char *buf, int len ) +do_read( conn_t *sock, char *buf, uint len ) { int n; assert( sock->fd >= 0 ); #ifdef HAVE_LIBSSL if (sock->ssl) { - if ((n = ssl_return( "read from", sock, SSL_read( sock->ssl, buf, len ) )) <= 0) + if ((n = ssl_return( "read from", sock, SSL_read( sock->ssl, buf, (int)len ) )) <= 0) return n; - if (n == len && SSL_pending( sock->ssl )) + if (n == (int)len && SSL_pending( sock->ssl )) conf_wakeup( &sock->ssl_fake, 0 ); } else #endif @@ -724,7 +724,8 @@ static void socket_fill_z( conn_t *sock ) { char *buf; - int len, ret; + uint len; + int ret; if (prepare_read( sock, &buf, &len ) < 0) return; @@ -744,7 +745,7 @@ socket_fill_z( conn_t *sock ) if (!sock->in_z->avail_out) conf_wakeup( &sock->z_fake, 0 ); - if ((len = (char *)sock->in_z->next_out - buf)) { + if ((len = (uint)((char *)sock->in_z->next_out - buf))) { sock->bytes += len; sock->read_callback( sock->callback_aux ); } @@ -762,21 +763,22 @@ socket_fill( conn_t *sock ) sock->in_z->next_in = (uchar *)sock->z_buf; if ((ret = do_read( sock, sock->z_buf, sizeof(sock->z_buf) )) <= 0) return; - sock->in_z->avail_in = ret; + sock->in_z->avail_in = (uint)ret; socket_fill_z( sock ); } else #endif { char *buf; - int len; + uint len; if (prepare_read( sock, &buf, &len ) < 0) return; - if ((len = do_read( sock, buf, len )) <= 0) + int n; + if ((n = do_read( sock, buf, len )) <= 0) return; - sock->bytes += len; + sock->bytes += (uint)n; sock->read_callback( sock->callback_aux ); } } @@ -789,9 +791,9 @@ socket_expect_activity( conn_t *conn, int expect ) } int -socket_read( conn_t *conn, char *buf, int len ) +socket_read( conn_t *conn, char *buf, uint len ) { - int n = conn->bytes; + uint n = conn->bytes; if (!n && conn->state == SCK_EOF) return -1; if (n > len) @@ -801,14 +803,14 @@ socket_read( conn_t *conn, char *buf, int len ) conn->offset = 0; else conn->offset += n; - return n; + return (int)n; } char * socket_read_line( conn_t *b ) { char *p, *s; - int n; + uint n; s = b->buf + b->offset; p = memchr( s + b->scanoff, '\n', b->bytes - b->scanoff ); @@ -822,7 +824,7 @@ socket_read_line( conn_t *b ) return (void *)~0; return 0; } - n = p + 1 - s; + n = (uint)(p + 1 - s); b->offset += n; b->bytes -= n; b->scanoff = 0; @@ -833,14 +835,14 @@ socket_read_line( conn_t *b ) } static int -do_write( conn_t *sock, char *buf, int len ) +do_write( conn_t *sock, char *buf, uint len ) { int n; assert( sock->fd >= 0 ); #ifdef HAVE_LIBSSL if (sock->ssl) - return ssl_return( "write to", sock, SSL_write( sock->ssl, buf, len ) ); + return ssl_return( "write to", sock, SSL_write( sock->ssl, buf, (int)len ) ); #endif n = write( sock->fd, buf, len ); if (n < 0) { @@ -851,7 +853,7 @@ do_write( conn_t *sock, char *buf, int len ) n = 0; conf_notifier( &sock->notify, POLLIN, POLLOUT ); } - } else if (n != len) { + } else if (n != (int)len) { conf_notifier( &sock->notify, POLLIN, POLLOUT ); } return n; @@ -876,11 +878,12 @@ do_queued_write( conn_t *conn ) return 0; while ((bc = conn->write_buf)) { - int n, len = bc->len - conn->write_offset; + int n; + uint len = bc->len - conn->write_offset; if ((n = do_write( conn, bc->data + conn->write_offset, len )) < 0) return -1; - if (n != len) { - conn->write_offset += n; + if (n != (int)len) { + conn->write_offset += (uint)n; conn->writing = 1; return 0; } @@ -915,7 +918,7 @@ do_flush( conn_t *conn ) buff_chunk_t *bc = conn->append_buf; #ifdef HAVE_LIBZ if (conn->out_z) { - int buf_avail = conn->append_avail; + uint buf_avail = conn->append_avail; if (!conn->z_written) return; do { @@ -936,7 +939,7 @@ do_flush( conn_t *conn ) error( "Fatal: Compression error: %s\n", z_err_msg( ret, conn->out_z ) ); abort(); } - bc->len = (char *)conn->out_z->next_out - bc->data; + bc->len = (uint)((char *)conn->out_z->next_out - bc->data); if (bc->len) { do_append( conn, bc ); bc = 0; @@ -962,7 +965,8 @@ do_flush( conn_t *conn ) void socket_write( conn_t *conn, conn_iovec_t *iov, int iovcnt ) { - int i, buf_avail, len, offset = 0, total = 0; + int i; + uint buf_avail, len, offset = 0, total = 0; buff_chunk_t *bc; for (i = 0; i < iovcnt; i++) @@ -1006,7 +1010,7 @@ socket_write( conn_t *conn, conn_iovec_t *iov, int iovcnt ) error( "Fatal: Compression error: %s\n", z_err_msg( ret, conn->out_z ) ); abort(); } - bc->len = (char *)conn->out_z->next_out - bc->data; + bc->len = (uint)((char *)conn->out_z->next_out - bc->data); buf_avail = conn->out_z->avail_out; len -= conn->out_z->avail_in; conn->z_written = 1; diff --git a/src/socket.h b/src/socket.h @@ -62,7 +62,7 @@ typedef struct { typedef struct buff_chunk { struct buff_chunk *next; - int len; + uint len; char data[1]; } buff_chunk_t; @@ -105,15 +105,15 @@ typedef struct { buff_chunk_t *write_buf, **write_buf_append; /* buffer head & tail */ int writing; #ifdef HAVE_LIBZ - int append_avail; /* space left in accumulating buffer */ + uint append_avail; /* space left in accumulating buffer */ #endif - int write_offset; /* offset into buffer head */ - int buffer_mem; /* memory currently occupied by buffers in the queue */ + uint write_offset; /* offset into buffer head */ + uint buffer_mem; /* memory currently occupied by buffers in the queue */ /* reading */ - int offset; /* start of filled bytes in buffer */ - int bytes; /* number of filled bytes in buffer */ - int scanoff; /* offset to continue scanning for newline at, relative to 'offset' */ + uint offset; /* start of filled bytes in buffer */ + uint bytes; /* number of filled bytes in buffer */ + uint scanoff; /* offset to continue scanning for newline at, relative to 'offset' */ char buf[100000]; #ifdef HAVE_LIBZ char z_buf[100000]; @@ -142,12 +142,12 @@ void socket_start_tls(conn_t *conn, void (*cb)( int ok, void *aux ) ); void socket_start_deflate( conn_t *conn ); void socket_close( conn_t *sock ); void socket_expect_activity( conn_t *sock, int expect ); -int socket_read( conn_t *sock, char *buf, int len ); /* never waits */ +int socket_read( conn_t *sock, char *buf, uint len ); /* never waits */ char *socket_read_line( conn_t *sock ); /* don't free return value; never waits */ typedef enum { KeepOwn = 0, GiveOwn } ownership_t; typedef struct { char *buf; - int len; + uint len; ownership_t takeOwn; } conn_iovec_t; void socket_write( conn_t *sock, conn_iovec_t *iov, int iovcnt ); diff --git a/src/sync.c b/src/sync.c @@ -102,10 +102,11 @@ Fprintf( FILE *f, const char *msg, ... ) /* The order is according to alphabetical maildir flag sort */ static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' }; -static int +static uchar parse_flags( const char *buf ) { - uint flags, i, d; + uint i, d; + uchar flags; for (flags = i = d = 0; i < as(Flags); i++) if (buf[d] == Flags[i]) { @@ -115,8 +116,8 @@ parse_flags( const char *buf ) return flags; } -static int -make_flags( int flags, char *buf ) +static uint +make_flags( uchar flags, char *buf ) { uint i, d; @@ -162,8 +163,9 @@ typedef struct { const char *orig_name[2]; message_t *msgs[2], *new_msgs[2]; uint_array_alloc_t trashed_msgs[2]; - int state[2], opts[2], ref_count, nsrecs, ret, lfd, existing, replayed; - int new_pending[2], flags_pending[2], trash_pending[2]; + int state[2], lfd, ret, existing, replayed; + uint ref_count, nsrecs, opts[2]; + uint new_pending[2], flags_pending[2], trash_pending[2]; uint maxuid[2]; // highest UID that was already propagated uint newmaxuid[2]; // highest UID that is currently being propagated uint uidval[2]; // UID validity value @@ -324,10 +326,10 @@ copy_msg( copy_vars_t *vars ) static void msg_stored( int sts, uint uid, void *aux ); static void -copy_msg_bytes( char **out_ptr, const char *in_buf, int *in_idx, int in_len, int in_cr, int out_cr ) +copy_msg_bytes( char **out_ptr, const char *in_buf, uint *in_idx, uint in_len, int in_cr, int out_cr ) { char *out = *out_ptr; - int idx = *in_idx; + uint idx = *in_idx; if (out_cr != in_cr) { char c; if (out_cr) { @@ -357,19 +359,19 @@ static int copy_msg_convert( int in_cr, int out_cr, copy_vars_t *vars ) { char *in_buf = vars->data.data; - int in_len = vars->data.len; - int idx = 0, sbreak = 0, ebreak = 0; - int lines = 0, hdr_crs = 0, bdy_crs = 0, app_cr = 0, extra = 0; + uint in_len = vars->data.len; + uint idx = 0, sbreak = 0, ebreak = 0; + uint lines = 0, hdr_crs = 0, bdy_crs = 0, app_cr = 0, extra = 0; if (vars->srec) { nloop: ; - int start = idx; - int line_crs = 0; + uint start = idx; + uint line_crs = 0; while (idx < in_len) { char c = in_buf[idx++]; if (c == '\r') { line_crs++; } else if (c == '\n') { - if (starts_with_upper( in_buf + start, in_len - start, "X-TUID: ", 8 )) { + if (starts_with_upper( in_buf + start, (int)(in_len - start), "X-TUID: ", 8 )) { extra = (sbreak = start) - (ebreak = idx); goto oke; } @@ -591,7 +593,7 @@ static char * clean_strdup( const char *s ) { char *cs; - int i; + uint i; cs = nfstrdup( s ); for (i = 0; cs[i]; i++) @@ -711,7 +713,7 @@ load_state( sync_vars_t *svars ) sync_rec_t *srec, *nsrec; char *s; FILE *jfp; - int ll; + uint ll; uint smaxxuid = 0; char c; struct stat st; @@ -863,7 +865,7 @@ load_state( sync_vars_t *svars ) goto jbail; } buf[ll] = 0; - if (!equals( buf, ll, JOURNAL_VERSION, strlen(JOURNAL_VERSION) )) { + if (!equals( buf, (int)ll, JOURNAL_VERSION, strlen(JOURNAL_VERSION) )) { error( "Error: incompatible journal version " "(got %s, expected " JOURNAL_VERSION ")\n", buf ); goto jbail; @@ -880,7 +882,7 @@ load_state( sync_vars_t *svars ) int tn; uint t1, t2, t3; if ((c = buf[0]) == '#' ? - (tn = 0, (sscanf( buf + 2, "%u %u %n", &t1, &t2, &tn ) < 2) || !tn || (ll - tn != TUIDL + 2)) : + (tn = 0, (sscanf( buf + 2, "%u %u %n", &t1, &t2, &tn ) < 2) || !tn || (ll - (uint)tn != TUIDL + 2)) : c == 'S' || c == '!' ? (sscanf( buf + 2, "%u", &t1 ) != 1) : c == 'F' || c == 'T' || c == '+' || c == '&' || c == '-' || c == '=' || c == '|' ? @@ -1202,8 +1204,7 @@ box_opened2( sync_vars_t *svars, int t ) channel_conf_t *chan; sync_rec_t *srec; uint_array_alloc_t mexcs; - uint minwuid; - int opts[2], fails; + uint opts[2], fails, minwuid; svars->state[t] |= ST_SELECTED; if (!(svars->state[1-t] & ST_SELECTED)) @@ -1260,7 +1261,7 @@ box_opened2( sync_vars_t *svars, int t ) opts[1-t] |= OPEN_NEW; if (chan->ops[t] & OP_EXPUNGE) opts[1-t] |= OPEN_FLAGS; - if (chan->stores[t]->max_size != INT_MAX) { + if (chan->stores[t]->max_size != UINT_MAX) { if (chan->ops[t] & OP_RENEW) opts[1-t] |= OPEN_FLAGS|OPEN_OLD_SIZE; if (chan->ops[t] & OP_NEW) @@ -1709,7 +1710,7 @@ box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux } } debug( "%d excess messages remain\n", todel ); - if (svars->chan->expire_unread < 0 && (uint)alive * 2 > svars->chan->max_messages) { + if (svars->chan->expire_unread < 0 && alive * 2 > svars->chan->max_messages) { error( "%s: %d unread messages in excess of MaxMessages (%d).\n" "Please set ExpireUnread to decide outcome. Skipping mailbox.\n", svars->orig_name[S], alive, svars->chan->max_messages ); @@ -1733,7 +1734,7 @@ box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux jFprintf( svars, "~ %u %u %u\n", srec->uid[M], srec->uid[S], srec->status ); } else { /* ... but the "right" transaction is already pending. */ - debug( " pair(%u,%u): %d (pending)\n", srec->uid[M], srec->uid[S], nex ); + debug( " pair(%u,%u): %u (pending)\n", srec->uid[M], srec->uid[S], nex ); } } else { /* Note: the "wrong" transaction may be pending here, diff --git a/src/sync.h b/src/sync.h @@ -52,7 +52,7 @@ typedef struct channel_conf { char *sync_state; string_list_t *patterns; int ops[2]; - uint max_messages; /* for slave only */ + int max_messages; /* for slave only */ signed char expire_unread; char use_internal_date; } channel_conf_t; diff --git a/src/util.c b/src/util.c @@ -170,7 +170,7 @@ sys_error( const char *msg, ... ) } void -add_string_list_n( string_list_t **list, const char *str, int len ) +add_string_list_n( string_list_t **list, const char *str, uint len ) { string_list_t *elem; @@ -210,7 +210,7 @@ vasprintf( char **strp, const char *fmt, va_list ap ) if (len >= (int)sizeof(tmp)) vsprintf( *strp, fmt, ap ); else - memcpy( *strp, tmp, len + 1 ); + memcpy( *strp, tmp, (size_t)len + 1 ); return len; } #endif @@ -239,34 +239,32 @@ strnlen( const char *str, size_t maxlen ) #endif int -starts_with( const char *str, int strl, const char *cmp, int cmpl ) +starts_with( const char *str, int strl, const char *cmp, uint cmpl ) { if (strl < 0) strl = strnlen( str, cmpl + 1 ); - return (strl >= cmpl) && !memcmp( str, cmp, cmpl ); + return ((uint)strl >= cmpl) && !memcmp( str, cmp, cmpl ); } int -starts_with_upper( const char *str, int strl, const char *cmp, int cmpl ) +starts_with_upper( const char *str, int strl, const char *cmp, uint cmpl ) { - int i; - if (strl < 0) strl = strnlen( str, cmpl + 1 ); - if (strl < cmpl) + if ((uint)strl < cmpl) return 0; - for (i = 0; i < cmpl; i++) + for (uint i = 0; i < cmpl; i++) if (str[i] != cmp[i] && toupper( str[i] ) != cmp[i]) return 0; return 1; } int -equals( const char *str, int strl, const char *cmp, int cmpl ) +equals( const char *str, int strl, const char *cmp, uint cmpl ) { if (strl < 0) strl = strnlen( str, cmpl + 1 ); - return (strl == cmpl) && !memcmp( str, cmp, cmpl ); + return ((uint)strl == cmpl) && !memcmp( str, cmp, cmpl ); } #ifndef HAVE_TIMEGM @@ -348,7 +346,7 @@ nfsnprintf( char *buf, int blen, const char *fmt, ... ) va_list va; va_start( va, fmt ); - if (blen <= 0 || (uint)(ret = vsnprintf( buf, blen, fmt, va )) >= (uint)blen) + if (blen <= 0 || (uint)(ret = vsnprintf( buf, (size_t)blen, fmt, va )) >= (uint)blen) oob(); va_end( va ); return ret; @@ -464,7 +462,7 @@ expand_strdup( const char *s ) q = Home; } else { if ((p = strchr( s, '/' ))) { - r = nfstrndup( s, (int)(p - s) ); + r = nfstrndup( s, (size_t)(p - s) ); pw = getpwnam( r ); free( r ); } else @@ -481,10 +479,10 @@ expand_strdup( const char *s ) /* Return value: 0 = ok, -1 = out found in arg, -2 = in found in arg but no out specified */ int -map_name( const char *arg, char **result, int reserve, const char *in, const char *out ) +map_name( const char *arg, char **result, uint reserve, const char *in, const char *out ) { char *p; - int i, l, ll, num, inl, outl; + uint i, l, ll, num, inl, outl; assert( arg ); l = strlen( arg ); @@ -498,7 +496,7 @@ map_name( const char *arg, char **result, int reserve, const char *in, const cha } assert( out ); outl = strlen( out ); - if (equals( in, inl, out, outl )) + if (equals( in, (int)inl, out, outl )) goto copy; for (num = 0, i = 0; i < l; ) { for (ll = 0; ll < inl; ll++) @@ -556,9 +554,9 @@ sort_uint_array( uint_array_t array ) int find_uint_array( uint_array_t array, uint value ) { - int bot = 0, top = array.size; + uint bot = 0, top = array.size; while (bot < top) { - int i = (bot + top) / 2; + uint i = (bot + top) / 2; uint elt = array.data[i]; if (elt == value) return 1; @@ -624,13 +622,13 @@ static const uchar prime_deltas[] = { 1, 29, 3, 21, 7, 17, 15, 9, 43, 35, 15, 0, 0, 0, 0, 0 }; -int -bucketsForSize( int size ) +uint +bucketsForSize( uint size ) { - int base = 4, bits = 2; + uint base = 4, bits = 2; for (;;) { - int prime = base + prime_deltas[bits]; + uint prime = base + prime_deltas[bits]; if (prime >= size) return prime; base <<= 1; @@ -665,7 +663,7 @@ static notifier_t *notifiers; static int changed; /* Iterator may be invalid now. */ #ifdef HAVE_SYS_POLL_H static struct pollfd *pollfds; -static int npolls, rpolls; +static uint npolls, rpolls; #else # ifdef HAVE_SYS_SELECT_H # include <sys/select.h> @@ -676,7 +674,7 @@ void init_notifier( notifier_t *sn, int fd, void (*cb)( int, void * ), void *aux ) { #ifdef HAVE_SYS_POLL_H - int idx = npolls++; + uint idx = npolls++; if (rpolls < npolls) { rpolls = npolls; pollfds = nfrealloc( pollfds, npolls * sizeof(*pollfds) ); @@ -698,7 +696,7 @@ void conf_notifier( notifier_t *sn, short and_events, short or_events ) { #ifdef HAVE_SYS_POLL_H - int idx = sn->index; + uint idx = sn->index; pollfds[idx].events = (pollfds[idx].events & and_events) | or_events; #else sn->events = (sn->events & and_events) | or_events; @@ -710,7 +708,7 @@ wipe_notifier( notifier_t *sn ) { notifier_t **snp; #ifdef HAVE_SYS_POLL_H - int idx; + uint idx; #endif for (snp = &notifiers; *snp != sn; snp = &(*snp)->next) @@ -813,7 +811,7 @@ event_wait( void ) break; } for (sn = notifiers; sn; sn = sn->next) { - int n = sn->index; + uint n = sn->index; if ((m = pollfds[n].revents)) { assert( !(m & POLLNVAL) ); sn->cb( m | shifted_bit( m, POLLHUP, POLLIN ), sn->aux );