From: Pietro Cerutti Date: Wed, 13 Dec 2017 13:17:52 +0000 (+0000) Subject: Review of "Bring consistency among sizes" X-Git-Tag: neomutt-20171215~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=81a63f7c419892246576727e4d5647129e918316;p=neomutt Review of "Bring consistency among sizes" Issue #928 --- diff --git a/address.c b/address.c index 74f1d1218..c3cd6427d 100644 --- a/address.c +++ b/address.c @@ -848,7 +848,7 @@ bool mutt_addr_valid_msgid(const char *msgid) return false; /* TODO: complete parser */ - for (unsigned int i = 0; i < l; i++) + for (size_t i = 0; i < l; i++) if ((unsigned char) msgid[i] > 127) return false; diff --git a/browser.c b/browser.c index a76cc95dd..faac9dc27 100644 --- a/browser.c +++ b/browser.c @@ -114,7 +114,7 @@ static char LastDir[_POSIX_PATH_MAX] = ""; */ static void destroy_state(struct BrowserState *state) { - for (int c = 0; c < state->entrylen; c++) + for (size_t c = 0; c < state->entrylen; c++) { FREE(&((state->entry)[c].name)); FREE(&((state->entry)[c].desc)); diff --git a/conn/ssl.c b/conn/ssl.c index 26e1387bf..79e006b4b 100644 --- a/conn/ssl.c +++ b/conn/ssl.c @@ -438,7 +438,7 @@ static void x509_fingerprint(char *s, int l, X509 *cert, const EVP_MD *(*hashfun } else { - for (int i = 0; i < (int) n; i++) + for (unsigned int i = 0; i < n; i++) { char ch[8]; snprintf(ch, 8, "%02X%s", md[i], (i % 2 ? " " : "")); @@ -1008,7 +1008,7 @@ static int interactive_check_cert(X509 *cert, int idx, size_t len, SSL *ssl, int snprintf(menu->dialog[row++], SHORT_STRING, _("MD5 Fingerprint: %s"), buf); snprintf(title, sizeof(title), - _("SSL Certificate check (certificate %d of %d in chain)"), len - idx, len); + _("SSL Certificate check (certificate %zu of %zu in chain)"), len - idx, len); menu->title = title; /* The leaf/host certificate can't be skipped. */ diff --git a/curs_main.c b/curs_main.c index 4654f9c02..7a6e98efc 100644 --- a/curs_main.c +++ b/curs_main.c @@ -700,10 +700,10 @@ int index_color(int index_no) */ void mutt_draw_statusline(int cols, const char *buf, int buflen) { - int i = 0; - int offset = 0; + size_t i = 0; + size_t offset = 0; bool found = false; - int chunks = 0; + size_t chunks = 0; size_t len = 0; struct Syntax @@ -785,7 +785,7 @@ void mutt_draw_statusline(int cols, const char *buf, int buflen) if (len <= syntax[i].last) goto dsl_finish; /* no more room */ - int next; + size_t next; if ((i + 1) == chunks) { next = len; diff --git a/imap/message.c b/imap/message.c index eba1dce51..b6bf35b89 100644 --- a/imap/message.c +++ b/imap/message.c @@ -473,7 +473,7 @@ static void flush_buffer(char *buf, size_t *len, struct Connection *conn) */ static void alloc_msn_index(struct ImapData *idata, size_t msn_count) { - unsigned int new_size; + size_t new_size; if (msn_count <= idata->msn_index_size) return; diff --git a/keymap.c b/keymap.c index 3ff760853..8efee03e3 100644 --- a/keymap.c +++ b/keymap.c @@ -183,9 +183,10 @@ static int parse_keycode(const char *s) return result; } -static int parsekeys(const char *str, keycode_t *d, int max) +static size_t parsekeys(const char *str, keycode_t *d, size_t max) { - int n, len = max; + int n; + size_t len = max; char buf[SHORT_STRING]; char c; char *s = NULL, *t = NULL; @@ -246,7 +247,7 @@ int km_bind_err(char *s, int menu, int op, char *macro, char *descr, struct Buff struct Keymap *map = NULL, *tmp = NULL, *last = NULL, *next = NULL; keycode_t buf[MAX_SEQ]; size_t len; - int pos = 0, lastpos = 0; + size_t pos = 0, lastpos = 0; len = parsekeys(s, buf, MAX_SEQ); diff --git a/mutt_address.c b/mutt_address.c index 2bef2095b..0be18f79e 100644 --- a/mutt_address.c +++ b/mutt_address.c @@ -148,7 +148,7 @@ done: * * Note: it is assumed that `buf' is nul terminated! */ -int rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int display) +size_t rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int display) { char *pbuf = buf; size_t len = mutt_str_strlen(buf); @@ -158,7 +158,7 @@ int rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int dis if (len > 0) { if (len > buflen) - return pbuf - buf; /* safety check for bogus arguments */ + return 0; /* safety check for bogus arguments */ pbuf += len; buflen -= len; diff --git a/muttlib.c b/muttlib.c index 70ece002a..159015a47 100644 --- a/muttlib.c +++ b/muttlib.c @@ -602,7 +602,7 @@ void mutt_pretty_mailbox(char *s, size_t buflen) } } -void mutt_pretty_size(char *s, size_t len, LOFF_T n) +void mutt_pretty_size(char *s, size_t len, size_t n) { if (n == 0) mutt_str_strfcpy(s, "0K", len); @@ -1410,6 +1410,10 @@ FILE *mutt_open_read(const char *path, pid_t *thepid) struct stat s; size_t len = mutt_str_strlen(path); + if (len == 0) + { + return NULL; + } if (path[len - 1] == '|') { diff --git a/parse.c b/parse.c index 9d6b2267f..0b28d37f2 100644 --- a/parse.c +++ b/parse.c @@ -583,11 +583,9 @@ struct Body *mutt_parse_multipart(FILE *fp, const char *boundary, LOFF_T end_off #ifdef SUN_ATTACHMENT int lines; #endif - size_t blen, len; - int crlf = 0; + size_t blen, len, crlf; char buffer[LONG_STRING]; struct Body *head = NULL, *last = NULL, *new = NULL; - int i; bool final = false; /* did we see the ending boundary? */ if (!boundary) @@ -617,7 +615,7 @@ struct Body *mutt_parse_multipart(FILE *fp, const char *boundary, LOFF_T end_off } /* Remove any trailing whitespace, up to the length of the boundary */ - for (i = len - 1; ISSPACE(buffer[i]) && i >= blen + 2; i--) + for (size_t i = len - 1; ISSPACE(buffer[i]) && i >= blen + 2; i--) buffer[i] = 0; /* Check for the end boundary */ diff --git a/protos.h b/protos.h index 2fd1ef2c6..f0877e394 100644 --- a/protos.h +++ b/protos.h @@ -208,7 +208,7 @@ void mutt_perror_debug(const char *s); void mutt_prepare_envelope(struct Envelope *env, int final); void mutt_unprepare_envelope(struct Envelope *env); void mutt_pretty_mailbox(char *s, size_t buflen); -void mutt_pretty_size(char *s, size_t len, LOFF_T n); +void mutt_pretty_size(char *s, size_t len, size_t n); void mutt_pipe_message(struct Header *h); void mutt_print_message(struct Header *h); void mutt_query_exit(void); @@ -373,7 +373,7 @@ int wcscasecmp(const wchar_t *a, const wchar_t *b); bool message_is_tagged(struct Context *ctx, int index); bool message_is_visible(struct Context *ctx, int index); -int rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int display); +size_t rfc822_write_address(char *buf, size_t buflen, struct Address *addr, int display); void rfc822_write_address_single(char *buf, size_t buflen, struct Address *addr, int display); #endif /* _MUTT_PROTOS_H */ diff --git a/url.c b/url.c index 58f73bdb8..c2eee6895 100644 --- a/url.c +++ b/url.c @@ -295,7 +295,8 @@ int url_tostring(struct Url *u, char *dest, size_t len, int flags) { if (!(flags & U_PATH)) mutt_str_strcat(dest, len, "//"); - len -= (l = strlen(dest)); + l = strlen(dest); + len -= l; dest += l; if (u->user && (u->user[0] || !(flags & U_PATH))) @@ -312,7 +313,8 @@ int url_tostring(struct Url *u, char *dest, size_t len, int flags) else snprintf(dest, len, "%s@", str); - len -= (l = strlen(dest)); + l = strlen(dest); + len -= l; dest += l; } @@ -321,7 +323,8 @@ int url_tostring(struct Url *u, char *dest, size_t len, int flags) else snprintf(dest, len, "%s", u->host); - len -= (l = strlen(dest)); + l = strlen(dest); + len -= l; dest += l; if (u->port) diff --git a/version.c b/version.c index 49b27d9b5..6d38c398d 100644 --- a/version.c +++ b/version.c @@ -295,8 +295,7 @@ static struct CompileOptions comp_opts[] = { */ static void print_compile_options(struct CompileOptions *co) { - size_t len; - int used = 2; + size_t len, used = 2; bool tty = stdout ? isatty(fileno(stdout)) : false; printf(" ");