From 5f45b7d53361bd32ce390e12f814660a98f86aa9 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Fri, 6 Oct 2017 13:15:28 +0200 Subject: [PATCH] use appropriate integer types Mainly found with clang -Wconversion -Wshorten-64-to-32. --- mgenmid.c | 2 +- mlist.c | 3 ++- mmime.c | 7 ++++--- mscan.c | 8 ++++---- mshow.c | 6 +++--- pipeto.c | 4 ++-- rfc2045.c | 2 +- rfc2047.c | 2 +- rfc2231.c | 4 ++-- seq.c | 6 +++--- 10 files changed, 23 insertions(+), 21 deletions(-) diff --git a/mgenmid.c b/mgenmid.c index a578bcc..497cbc4 100644 --- a/mgenmid.c +++ b/mgenmid.c @@ -103,7 +103,7 @@ fallback: rnd = ((uint64_t)lrand48() << 32) + lrand48(); } - rnd |= (1LL << 63); // set highest bit to force full width + rnd |= (1ULL << 63); // set highest bit to force full width putchar('<'); printb36(((uint64_t)tp.tv_sec * 1000000LL + tp.tv_usec)); diff --git a/mlist.c b/mlist.c index 085fe7d..ddc23c9 100644 --- a/mlist.c +++ b/mlist.c @@ -109,7 +109,8 @@ struct linux_dirent64 { void listdir(char *dir) { - int fd, nread; + int fd; + ssize_t nread; char buf[BUF_SIZE]; struct linux_dirent64 *d; int bpos; diff --git a/mmime.c b/mmime.c index e8426d1..1f16d5a 100644 --- a/mmime.c +++ b/mmime.c @@ -57,7 +57,8 @@ int gen_b64(uint8_t *s, off_t size) return 0; } -int gen_qp(uint8_t *s, off_t size, int maxlinelen, int linelen) +size_t +gen_qp(uint8_t *s, off_t size, size_t maxlinelen, size_t linelen) { off_t i; int header = linelen > 0; @@ -298,7 +299,7 @@ print_header(char *line) { int prevq = 0; // was the previous word encoded as qp? - int linelen = s - line; + size_t linelen = s - line; while (*s) { size_t highbit = 0; @@ -365,7 +366,7 @@ gen_build() int intext = 0; while (1) { - int read = getdelim(&line, &linelen, '\n', stdin); + ssize_t read = getdelim(&line, &linelen, '\n', stdin); if (read == -1) { if (feof(stdin)) break; diff --git a/mscan.c b/mscan.c index 8d104ad..08dbc90 100644 --- a/mscan.c +++ b/mscan.c @@ -33,7 +33,7 @@ static time_t now; static char default_fflag[] = "%c%u%r %-3n %10d %17f %t %2i%s"; static char *fflag = default_fflag; -int +ssize_t u8putstr(FILE *out, char *s, ssize_t l, int pad) { ssize_t ol = l; @@ -109,7 +109,7 @@ numline(char *file) } static char * -fmt_date(struct message *msg, int w, int iso) +fmt_date(struct message *msg, long w, int iso) { static char date[32]; char *v; @@ -244,7 +244,7 @@ fmt_to_flag(struct message *msg) } static ssize_t -print_human(intmax_t i, int w) +print_human(intmax_t i, long w) { double d = i / 1024.0; const char *u = "\0\0M\0G\0T\0P\0E\0Z\0Y\0"; @@ -310,7 +310,7 @@ oneline(char *file) } f++; - int w = 0; + long w = 0; if ((*f >= '0' && *f <= '9') || *f == '-') { errno = 0; char *e; diff --git a/mshow.c b/mshow.c index eff8c76..5f24d75 100644 --- a/mshow.c +++ b/mshow.c @@ -45,7 +45,7 @@ printable(int c) return (unsigned)c-0x20 < 0x5f; } -int +size_t print_ascii(char *body, size_t bodylen) { if (safe_output) { @@ -567,7 +567,7 @@ print_date_header(char *v) printf(" ("); time_t d = t < now ? now - t : t - now; - int l; + char l; if (d > 60*60*24*7*52) l = 'y'; else if (d > 60*60*24*7) l = 'w'; else if (d > 60*60*24) l = 'd'; @@ -576,7 +576,7 @@ print_date_header(char *v) else l = 's'; int p = 3; - int z; + long z; switch (l) { case 'y': z = d / (60*60*24*7*52); diff --git a/pipeto.c b/pipeto.c index 4392548..c2bae0c 100644 --- a/pipeto.c +++ b/pipeto.c @@ -57,14 +57,14 @@ pipeto(const char *cmdline) errno = EINVAL; // execvp failed, write errno to parent - long e = errno; + int e = errno; if (write(pipe1[1], &e, sizeof e) < 0) exit(111); // do a magic dance for gcc -Wunused-result exit(111); } else { // in parent close(pipe1[1]); - long e; + int e; ssize_t n = read(pipe1[0], &e, sizeof e); if (n < 0) e = errno; diff --git a/rfc2045.c b/rfc2045.c index a0e5470..807a0c3 100644 --- a/rfc2045.c +++ b/rfc2045.c @@ -129,7 +129,7 @@ blaze822_multipart(struct message *msg, struct message **imsg) if (!blaze822_mime_parameter(s, "boundary", &boundary, &boundaryend)) return 0; char mboundary[256]; - int boundarylen = boundaryend-boundary+2; + size_t boundarylen = boundaryend-boundary+2; if (boundarylen >= 256) return 0; diff --git a/rfc2047.c b/rfc2047.c index 6d4760a..f739269 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -215,7 +215,7 @@ blaze822_decode_rfc2047(char *dst, char *src, size_t dlen, char *tgtenc) } decchunk = dec; - int r = iconv(ic, &dec, &declen, &dst, &dlen); + ssize_t r = iconv(ic, &dec, &declen, &dst, &dlen); if (r < 0) { if (errno == E2BIG) { break; diff --git a/rfc2231.c b/rfc2231.c index c0edaff..cc36970 100644 --- a/rfc2231.c +++ b/rfc2231.c @@ -111,8 +111,8 @@ found_plain: size_t dstlen = dst - dststart; dst = dststart; - int r = iconv(ic, &dst, &dstlen, &tmpend, &tmplen); - if (r < 0) { + size_t r = iconv(ic, &dst, &dstlen, &tmpend, &tmplen); + if (r == (size_t)-1) { free(tmp); return 1; } diff --git a/seq.c b/seq.c index 84a77e1..8a8203a 100644 --- a/seq.c +++ b/seq.c @@ -142,7 +142,7 @@ blaze822_seq_cur(void) if (!curlink) curlink = blaze822_home_file("cur"); - int r = readlink(curlink, b, sizeof b - 1); + ssize_t r = readlink(curlink, b, sizeof b - 1); if (r < 0) return 0; b[r] = 0; @@ -308,14 +308,14 @@ parse_parent(char *map, long *starto, long *stopo) char *s, *t; long line; - int previndent[256] = { 0 }; + long previndent[256] = { 0 }; for (s = map, line = 0; s; s = t+1) { t = strchr(s, '\n'); if (!t) break; line++; - int indent = 0; + long indent = 0; while (*s && iswsp(*s)) { s++; indent++;