From 92720000ded3c12dd14eb29ceee60d1bcafd87f2 Mon Sep 17 00:00:00 2001 From: Federico Kircheis Date: Fri, 2 Mar 2018 19:48:26 +0100 Subject: [PATCH] Reduce variable scope - handler.c --- handler.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/handler.c b/handler.c index f56568e906b..d1ed178cc56 100644 --- a/handler.c +++ b/handler.c @@ -235,11 +235,8 @@ static void decode_quoted(struct State *s, long len, int istext, iconv_t cd) char line[STRING]; char decline[2 * STRING]; size_t l = 0; - size_t linelen; /* number of input bytes in `line' */ size_t l3; - int last; /* store the last character in the input line */ - if (istext) state_set_prefix(s); @@ -255,14 +252,14 @@ static void decode_quoted(struct State *s, long len, int istext, iconv_t cd) if (fgets(line, MIN((ssize_t) sizeof(line), len + 1), s->fpin) == NULL) break; - linelen = strlen(line); + size_t linelen = strlen(line); len -= linelen; /* * inspect the last character we read so we can tell if we got the * entire line. */ - last = linelen ? line[linelen - 1] : 0; + const int last = linelen ? line[linelen - 1] : 0; /* chop trailing whitespace if we got the full line */ if (last == '\n') @@ -285,7 +282,7 @@ static void decode_quoted(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; + int ch, i; char bufi[BUFI_SIZE]; size_t l = 0; @@ -312,20 +309,20 @@ void mutt_decode_base64(struct State *s, size_t len, int istext, iconv_t cd) break; } - c1 = base64val(buf[0]); - c2 = base64val(buf[1]); + const int c1 = base64val(buf[0]); + const int c2 = base64val(buf[1]); ch = (c1 << 2) | (c2 >> 4); bufi[l++] = ch; if (buf[2] == '=') break; - c3 = base64val(buf[2]); + const int c3 = base64val(buf[2]); ch = ((c2 & 0xf) << 4) | (c3 >> 2); bufi[l++] = ch; if (buf[3] == '=') break; - c4 = base64val(buf[3]); + const int c4 = base64val(buf[3]); ch = ((c3 & 0x3) << 6) | c4; bufi[l++] = ch; @@ -349,7 +346,7 @@ static unsigned char decode_byte(char ch) static void decode_uuencoded(struct State *s, long len, int istext, iconv_t cd) { char tmps[SHORT_STRING]; - char linelen, c, l, out; + char linelen; char *pt = NULL; char bufi[BUFI_SIZE]; size_t k = 0; @@ -375,11 +372,11 @@ static void decode_uuencoded(struct State *s, long len, int istext, iconv_t cd) pt = tmps; linelen = decode_byte(*pt); pt++; - for (c = 0; c < linelen;) + for (char c = 0; c < linelen;) { - for (l = 2; l <= 6; l += 2) + for (char l = 2; l <= 6; l += 2) { - out = decode_byte(*pt) << l; + char out = decode_byte(*pt) << l; pt++; out |= (decode_byte(*pt) >> (6 - l)); bufi[k++] = out; @@ -471,7 +468,6 @@ struct EnrichedState static void enriched_wrap(struct EnrichedState *stte) { int x; - int extra; if (stte->line_len) { @@ -507,7 +503,7 @@ static void enriched_wrap(struct EnrichedState *stte) } } - extra = stte->wrap_margin - stte->line_len - stte->indent_len - + const int extra = stte->wrap_margin - stte->line_len - stte->indent_len - (stte->tag_level[RICH_INDENT_RIGHT] * INDENT_SIZE); if (extra > 0) { @@ -912,7 +908,6 @@ static int is_mmnoask(const char *buf) char *p = NULL; const char *val = NULL; char tmp[LONG_STRING], *q = NULL; - int lng; val = mutt_str_getenv("MM_NOASK"); if (val) @@ -941,7 +936,7 @@ static int is_mmnoask(const char *buf) } else { - lng = mutt_str_strlen(p); + const int lng = mutt_str_strlen(p); if (buf[lng] == '/' && (mutt_str_strncasecmp(buf, p, lng) == 0)) return 1; } @@ -1009,10 +1004,8 @@ static int alternative_handler(struct Body *a, struct State *s) { struct Body *choice = NULL; struct Body *b = NULL; - int type = 0; bool mustfree = false; int rc = 0; - int count = 0; if (a->encoding == ENCBASE64 || a->encoding == ENCQUOTEDPRINTABLE || a->encoding == ENCUUENCODED) { @@ -1094,6 +1087,7 @@ static int alternative_handler(struct Body *a, struct State *s) b = a->parts; else b = a; + int type = 0; while (b) { if (b->type == TYPETEXT) @@ -1153,6 +1147,7 @@ static int alternative_handler(struct Body *a, struct State *s) b = a->parts; else b = a; + int count = 0; while (b) { if (choice != b) @@ -1501,13 +1496,13 @@ static int external_body_handler(struct Body *b, struct State *s) if (s->flags & (MUTT_DISPLAY | MUTT_PRINTING)) { char *length = NULL; - char pretty_size[10]; state_mark_attach(s); state_printf(s, _("[-- This %s/%s attachment "), TYPE(b->parts), b->parts->subtype); length = mutt_param_get(&b->parameter, "length"); if (length) { + char pretty_size[10]; mutt_str_pretty_size(pretty_size, sizeof(pretty_size), strtol(length, NULL, 10)); state_printf(s, _("(size %s bytes) "), pretty_size); } @@ -1638,12 +1633,8 @@ static int text_plain_handler(struct Body *b, struct State *s) static int run_decode_and_handler(struct Body *b, struct State *s, handler_t handler, int plaintext) { - int orig_type; char *save_prefix = NULL; FILE *fp = NULL; -#ifndef USE_FMEMOPEN - char tempfile[_POSIX_PATH_MAX]; -#endif size_t tmplength = 0; LOFF_T tmpoffset = 0; int decode = 0; @@ -1664,8 +1655,10 @@ static int run_decode_and_handler(struct Body *b, struct State *s, * with 8bit encoding. */ { - orig_type = b->type; - + const int orig_type = b->type; +#ifndef USE_FMEMOPEN + char tempfile[_POSIX_PATH_MAX]; +#endif if (!plaintext) { /* decode to a tempfile, saving the original destination */