From: Justin Vasel Date: Wed, 29 Nov 2017 18:00:44 +0000 (-0500) Subject: Bring consistency among sizes X-Git-Tag: neomutt-20171215~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b310689426c102b8864af25c7f6899886db4d7f1;p=neomutt Bring consistency among sizes There are instances in the code that refer to lengths or sizes of strings and buffers and the like, but they are not typed in a consistent manner. The purpose of this commit is to provide some consistency to these scenarios by changing their type from unsigned int, int, unsigned long, etc. to size_t. In general, these situations were identified by globally searching the code for patterns along the lines of: (unsigned|unsigned int|int|long) (len|blen|olen|length|l|size) and changing the type to size_t on a case-by-case basis. The following situations were explicitly ignored: - autosetup/jimsh0.c, because it appears to be third-party code - inputs to function calls relating to ssl and sasl, because they don't take size_t as inputs and recasting in the function call didn't seem worth the increased messiness - for loop indices, because in some cases unsigned indices can breed bugs This commit takes care of most obvious cases. There may certainly be subtler ones that were missed in this pass. Resolves: #928 --- diff --git a/address.c b/address.c index 1acb7c519..74f1d1218 100644 --- a/address.c +++ b/address.c @@ -834,7 +834,7 @@ bool mutt_addr_valid_msgid(const char *msgid) * domain-literal = "[" *(dtext / quoted-pair) "]" */ - unsigned int l; + size_t l; if (!msgid || !*msgid) return false; diff --git a/attach.c b/attach.c index 97ab4b77f..87d1a7e0d 100644 --- a/attach.c +++ b/attach.c @@ -307,7 +307,7 @@ bailout: * @param type Buffer with mime type of attachment in "type/subtype" format * @param len Buffer length */ -void mutt_check_lookup_list(struct Body *b, char *type, int len) +void mutt_check_lookup_list(struct Body *b, char *type, size_t len) { int i; diff --git a/browser.c b/browser.c index e261086d7..a76cc95dd 100644 --- a/browser.c +++ b/browser.c @@ -1696,7 +1696,7 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi #endif { /* add '/' at the end of the directory name if not already there */ - int len = mutt_str_strlen(buf); + size_t len = mutt_str_strlen(buf); if ((len > 0) && (buf[len - 1] != '/') && (sizeof(buf) > (len + 1))) { buf[len] = '/'; diff --git a/browser.h b/browser.h index d84af292f..ca7925163 100644 --- a/browser.h +++ b/browser.h @@ -67,7 +67,7 @@ struct FolderFile struct BrowserState { struct FolderFile *entry; - unsigned int entrylen; /**< number of real entries */ + size_t entrylen; /**< number of real entries */ unsigned int entrymax; /**< max entry */ #ifdef USE_IMAP bool imap_browse; diff --git a/conn/ssl.c b/conn/ssl.c index d10d055e7..26e1387bf 100644 --- a/conn/ssl.c +++ b/conn/ssl.c @@ -947,7 +947,7 @@ static int ssl_cache_trusted_cert(X509 *c) * @retval true User selected 'skip' * @retval false Otherwise */ -static int interactive_check_cert(X509 *cert, int idx, int len, SSL *ssl, int allow_always) +static int interactive_check_cert(X509 *cert, int idx, size_t len, SSL *ssl, int allow_always) { static const int part[] = { NID_commonName, /* CN */ @@ -1121,7 +1121,8 @@ static int ssl_verify_callback(int preverify_ok, X509_STORE_CTX *ctx) { char buf[STRING]; const char *host = NULL; - int len, pos; + size_t len; + int pos; X509 *cert = NULL; SSL *ssl = NULL; int skip_mode; diff --git a/copy.c b/copy.c index e0b473c93..5969b887c 100644 --- a/copy.c +++ b/copy.c @@ -278,7 +278,7 @@ int mutt_copy_hdr(FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, } else { - int blen = mutt_str_strlen(buf); + size_t blen = mutt_str_strlen(buf); mutt_mem_realloc(&this_one, this_one_len + blen + sizeof(char)); strcat(this_one + this_one_len, buf); @@ -898,7 +898,7 @@ static void format_address_header(char **h, struct Address *a) char cbuf[STRING]; char c2buf[STRING]; char *p = NULL; - int l, linelen, buflen, cbuflen, c2buflen, plen; + size_t l, linelen, buflen, cbuflen, c2buflen, plen; linelen = mutt_str_strlen(*h); plen = linelen; @@ -954,7 +954,7 @@ static void format_address_header(char **h, struct Address *a) static int address_header_decode(char **h) { char *s = *h; - int l; + size_t l; bool rp = false; struct Address *a = NULL; diff --git a/curs_lib.c b/curs_lib.c index 19b0aa75f..773fd80eb 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -449,7 +449,7 @@ void mutt_curses_message(const char *fmt, ...) } void mutt_progress_init(struct Progress *progress, const char *msg, - unsigned short flags, unsigned short inc, long size) + unsigned short flags, unsigned short inc, size_t size) { struct timeval tv = { 0, 0 }; diff --git a/curs_main.c b/curs_main.c index 05930b5bb..4654f9c02 100644 --- a/curs_main.c +++ b/curs_main.c @@ -704,7 +704,7 @@ void mutt_draw_statusline(int cols, const char *buf, int buflen) int offset = 0; bool found = false; int chunks = 0; - int len = 0; + size_t len = 0; struct Syntax { diff --git a/handler.c b/handler.c index d11485c24..f93c2dc01 100644 --- a/handler.c +++ b/handler.c @@ -303,7 +303,7 @@ static void decode_quoted(struct State *s, long len, int istext, iconv_t cd) state_reset_prefix(s); } -void mutt_decode_base64(struct State *s, long len, int istext, iconv_t cd) +void mutt_decode_base64(struct State *s, size_t len, int istext, iconv_t cd) { char buf[5]; int c1, c2, c3, c4, ch, i; diff --git a/hdrline.c b/hdrline.c index e96821416..49fa35ffa 100644 --- a/hdrline.c +++ b/hdrline.c @@ -158,7 +158,7 @@ static bool first_mailing_list(char *buf, size_t buflen, struct Address *a) */ static size_t add_index_color(char *buf, size_t buflen, enum FormatFlag flags, char color) { - int len; + size_t len; /* only add color markers if we are operating on main index entries. */ if (!(flags & MUTT_FORMAT_INDEX)) diff --git a/imap/auth_cram.c b/imap/auth_cram.c index d159ee782..86f6bbcae 100644 --- a/imap/auth_cram.c +++ b/imap/auth_cram.c @@ -58,7 +58,7 @@ static void hmac_md5(const char *password, char *challenge, unsigned char *respo unsigned char ipad[MD5_BLOCK_LEN], opad[MD5_BLOCK_LEN]; unsigned char secret[MD5_BLOCK_LEN + 1]; unsigned char hash_passwd[MD5_DIGEST_LEN]; - unsigned int secret_len, chal_len; + size_t secret_len, chal_len; secret_len = strlen(password); chal_len = strlen(challenge); diff --git a/imap/imap_private.h b/imap/imap_private.h index 508d00115..cc565cd89 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -222,7 +222,7 @@ struct ImapData unsigned int seqno; time_t lastread; /**< last time we read a command for the server */ char *buf; - unsigned int blen; + size_t blen; /* If nonzero, we can send UTF-8, and the server will use UTF8 rather * than mUTF7 */ @@ -255,7 +255,7 @@ struct ImapData unsigned int uid_validity; unsigned int uidnext; struct Header **msn_index; /**< look up headers by (MSN-1) */ - unsigned int msn_index_size; /**< allocation size */ + size_t msn_index_size; /**< allocation size */ unsigned int max_msn; /**< the largest MSN fetched so far */ struct BodyCache *bcache; diff --git a/imap/message.c b/imap/message.c index 4a87e46dc..eba1dce51 100644 --- a/imap/message.c +++ b/imap/message.c @@ -471,7 +471,7 @@ static void flush_buffer(char *buf, size_t *len, struct Connection *conn) * * Mapping from Message Sequence Number to Header */ -static void alloc_msn_index(struct ImapData *idata, unsigned int msn_count) +static void alloc_msn_index(struct ImapData *idata, size_t msn_count) { unsigned int new_size; diff --git a/init.c b/init.c index 612954ebd..98504998e 100644 --- a/init.c +++ b/init.c @@ -1580,7 +1580,7 @@ static int parse_attach_list(struct Buffer *buf, struct Buffer *s, struct AttachMatch *a = NULL; char *p = NULL; char *tmpminor = NULL; - int len; + size_t len; int ret; do @@ -3399,7 +3399,7 @@ static void matches_ensure_morespace(int current) * * Changes the dest buffer if necessary/possible to aid completion. */ -static void candidate(char *dest, char *try, const char *src, int len) +static void candidate(char *dest, char *try, const char *src, size_t len) { if (!dest || !try || !src) return; diff --git a/keymap.c b/keymap.c index 40591c55a..3ff760853 100644 --- a/keymap.c +++ b/keymap.c @@ -130,7 +130,7 @@ int LastKey; struct Keymap *Keymaps[MENU_MAX]; -static struct Keymap *alloc_keys(int len, keycode_t *keys) +static struct Keymap *alloc_keys(size_t len, keycode_t *keys) { struct Keymap *p = NULL; @@ -245,7 +245,8 @@ int km_bind_err(char *s, int menu, int op, char *macro, char *descr, struct Buff int retval = 0; struct Keymap *map = NULL, *tmp = NULL, *last = NULL, *next = NULL; keycode_t buf[MAX_SEQ]; - int len, pos = 0, lastpos = 0; + size_t len; + int pos = 0, lastpos = 0; len = parsekeys(s, buf, MAX_SEQ); diff --git a/mutt_charset.c b/mutt_charset.c index 7b9bb5772..f783a6366 100644 --- a/mutt_charset.c +++ b/mutt_charset.c @@ -97,7 +97,7 @@ int mutt_convert_string(char **ps, const char *from, const char *to, int flags) if (to && from && (cd = mutt_iconv_open(to, from, flags)) != (iconv_t) -1) { - int len; + size_t len; const char *ib = NULL; char *buf = NULL, *ob = NULL; size_t ibl, obl; diff --git a/mutt_curses.h b/mutt_curses.h index 0f4f068e2..83cc779b6 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -213,13 +213,13 @@ struct Progress unsigned short flags; const char *msg; long pos; - long size; + size_t size; unsigned int timestamp; char sizestr[SHORT_STRING]; }; void mutt_progress_init(struct Progress *progress, const char *msg, - unsigned short flags, unsigned short inc, long size); + unsigned short flags, unsigned short inc, size_t size); /* If percent is positive, it is displayed as percentage, otherwise * percentage is calculated from progress->size and pos if progress * was initialized with positive size, otherwise no percentage is shown */ diff --git a/muttlib.c b/muttlib.c index a7e3f79fd..70ece002a 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1409,7 +1409,7 @@ FILE *mutt_open_read(const char *path, pid_t *thepid) FILE *f = NULL; struct stat s; - int len = mutt_str_strlen(path); + size_t len = mutt_str_strlen(path); if (path[len - 1] == '|') { diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 8d366147d..fd134f8aa 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -489,7 +489,7 @@ int mutt_is_application_pgp(struct Body *m) int mutt_is_application_smime(struct Body *m) { char *t = NULL; - int len; + size_t len; bool complain = false; if (!m) diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index bf7933032..d1cb04d58 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -584,7 +584,7 @@ static gpgme_data_t body_to_data_object(struct Body *a, int convert) * Create a GPGME data object from the stream FP but limit the object * to LENGTH bytes starting at OFFSET bytes from the beginning of the file. */ -static gpgme_data_t file_to_data_object(FILE *fp, long offset, long length) +static gpgme_data_t file_to_data_object(FILE *fp, long offset, size_t length) { int err = 0; gpgme_data_t data; @@ -2168,7 +2168,7 @@ static int pgp_gpgme_extract_keys(gpgme_data_t keydata, FILE **fp, int dryrun) gpgme_user_id_t uid; gpgme_subkey_t subkey; const char *shortid = NULL; - int len; + size_t len; char date[STRING]; int more; int rc = -1; diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 08b874241..609c23ea4 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -830,7 +830,7 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, FILE *pgpin = NULL, *pgpout = NULL, *pgperr = NULL, *pgptmp = NULL; struct stat info; struct Body *tattach = NULL; - int len; + size_t len; char pgperrfile[_POSIX_PATH_MAX]; char pgptmpfile[_POSIX_PATH_MAX]; pid_t thepid; diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 6dd652429..014acb7dc 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -1748,7 +1748,7 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) */ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *out_file) { - int len = 0; + size_t len = 0; int c; char buf[HUGE_STRING]; char outfile[_POSIX_PATH_MAX], errfile[_POSIX_PATH_MAX]; diff --git a/newsrc.c b/newsrc.c index bbcad4535..ae162cb31 100644 --- a/newsrc.c +++ b/newsrc.c @@ -64,7 +64,7 @@ static struct NntpData *nntp_data_find(struct NntpServer *nserv, const char *gro if (!nntp_data) { - int len = strlen(group) + 1; + size_t len = strlen(group) + 1; /* create NntpData structure and add it to hash */ nntp_data = mutt_mem_calloc(1, sizeof(struct NntpData) + len); nntp_data->group = (char *) nntp_data + sizeof(struct NntpData); diff --git a/nntp.c b/nntp.c index 5f84ad53d..fa5add077 100644 --- a/nntp.c +++ b/nntp.c @@ -298,7 +298,7 @@ static int nntp_attempt_features(struct NntpServer *nserv) off = colon + 1 - nserv->overview_fmt; if (strcasecmp(nserv->overview_fmt + b, "Bytes:") == 0) { - int len = strlen(nserv->overview_fmt + b); + size_t len = strlen(nserv->overview_fmt + b); mutt_str_strfcpy(nserv->overview_fmt + b, "Content-Length:", len + 1); off = b + len; } diff --git a/pager.c b/pager.c index fa211a047..b75172347 100644 --- a/pager.c +++ b/pager.c @@ -120,7 +120,7 @@ static struct Header *OldHdr = NULL; */ struct QClass { - int length; + size_t length; int index; int color; char *prefix; @@ -433,7 +433,7 @@ static void cleanup_quote(struct QClass **quote_list) } static struct QClass *classify_quote(struct QClass **quote_list, const char *qptr, - int length, int *force_redraw, int *q_level) + size_t length, int *force_redraw, int *q_level) { struct QClass *q_list = *quote_list; struct QClass *class = NULL, *tmp = NULL, *ptr = NULL, *save = NULL; diff --git a/parse.c b/parse.c index 4d83405dd..9d6b2267f 100644 --- a/parse.c +++ b/parse.c @@ -583,7 +583,8 @@ struct Body *mutt_parse_multipart(FILE *fp, const char *boundary, LOFF_T end_off #ifdef SUN_ATTACHMENT int lines; #endif - int blen, len, crlf = 0; + size_t blen, len; + int crlf = 0; char buffer[LONG_STRING]; struct Body *head = NULL, *last = NULL, *new = NULL; int i; diff --git a/pgppubring.c b/pgppubring.c index f724ec88a..93e1c02cf 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -203,7 +203,7 @@ static bool pgpring_string_matches_hint(const char *s, const char *hints[], int static void pgp_make_pgp2_fingerprint(unsigned char *buf, unsigned char *digest) { struct Md5Ctx ctx; - unsigned int size = 0; + size_t size = 0; mutt_md5_init_ctx(&ctx); diff --git a/pop.c b/pop.c index aa4390231..6ba4fb09b 100644 --- a/pop.c +++ b/pop.c @@ -83,7 +83,7 @@ static int pop_read_header(struct PopData *pop_data, struct Header *h) { FILE *f = NULL; int rc, index; - long length; + size_t length; char buf[LONG_STRING]; char tempfile[_POSIX_PATH_MAX]; @@ -99,7 +99,7 @@ static int pop_read_header(struct PopData *pop_data, struct Header *h) rc = pop_query(pop_data, buf, sizeof(buf)); if (rc == 0) { - sscanf(buf, "+OK %d %ld", &index, &length); + sscanf(buf, "+OK %d %zu", &index, &length); snprintf(buf, sizeof(buf), "TOP %d 0\r\n", h->refno); rc = pop_fetch_data(pop_data, buf, NULL, fetch_message, f); diff --git a/protos.h b/protos.h index b1a39cc8a..2fd1ef2c6 100644 --- a/protos.h +++ b/protos.h @@ -157,7 +157,7 @@ void mutt_check_rescore(struct Context *ctx); void mutt_clear_error(void); void mutt_clear_pager_position(void); void mutt_decode_attachment(struct Body *b, struct State *s); -void mutt_decode_base64(struct State *s, long len, int istext, iconv_t cd); +void mutt_decode_base64(struct State *s, size_t len, int istext, iconv_t cd); void mutt_default_save(char *path, size_t pathlen, struct Header *hdr); void mutt_display_address(struct Envelope *env); void mutt_draw_statusline(int cols, const char *buf, int buflen); @@ -191,7 +191,7 @@ void mutt_free_color(int fg, int bg); void mutt_free_enter_state(struct EnterState **esp); void mutt_free_regex(struct Regex **pp); void mutt_help(int menu); -void mutt_check_lookup_list(struct Body *b, char *type, int len); +void mutt_check_lookup_list(struct Body *b, char *type, size_t len); void mutt_make_attribution(struct Context *ctx, struct Header *cur, FILE *out); void mutt_make_forward_subject(struct Envelope *env, struct Context *ctx, struct Header *cur); void mutt_make_help(char *d, size_t dlen, const char *txt, int menu, int op); diff --git a/sendlib.c b/sendlib.c index 19a72b014..dcc3081ad 100644 --- a/sendlib.c +++ b/sendlib.c @@ -315,7 +315,7 @@ int mutt_write_mime_header(struct Body *a, FILE *f) char buffer[STRING]; char *t = NULL; char *fn = NULL; - int len; + size_t len; int tmplen; int encode; @@ -1613,7 +1613,7 @@ void mutt_write_address_list(struct Address *adr, FILE *fp, int linelen, int dis struct Address *tmp = NULL; char buf[LONG_STRING]; int count = 0; - int len; + size_t len; while (adr) { diff --git a/sidebar.c b/sidebar.c index b31227ae3..17d3b53ef 100644 --- a/sidebar.c +++ b/sidebar.c @@ -252,7 +252,7 @@ static const char *sidebar_format_str(char *buf, size_t buflen, size_t col, int * mutt_expando_format to do the actual work. mutt_expando_format will callback to * us using sidebar_format_str() for the sidebar specific formatting characters. */ -static void make_sidebar_entry(char *buf, unsigned int buflen, int width, +static void make_sidebar_entry(char *buf, size_t buflen, int width, char *box, struct SbEntry *sbe) { if (!buf || !box || !sbe) @@ -276,7 +276,7 @@ static void make_sidebar_entry(char *buf, unsigned int buflen, int width, else if (w > width) { /* Truncate to fit */ - int len = mutt_wstr_trunc(buf, buflen, width, NULL); + size_t len = mutt_wstr_trunc(buf, buflen, width, NULL); buf[len] = 0; } } diff --git a/url.c b/url.c index 4bcdca47b..58f73bdb8 100644 --- a/url.c +++ b/url.c @@ -284,7 +284,7 @@ void url_pct_encode(char *dst, size_t l, const char *src) */ int url_tostring(struct Url *u, char *dest, size_t len, int flags) { - long l; + size_t l; if (u->scheme == U_UNKNOWN) return -1; diff --git a/version.c b/version.c index 00e28a382..49b27d9b5 100644 --- a/version.c +++ b/version.c @@ -295,7 +295,7 @@ static struct CompileOptions comp_opts[] = { */ static void print_compile_options(struct CompileOptions *co) { - int len; + size_t len; int used = 2; bool tty = stdout ? isatty(fileno(stdout)) : false;