From d1ee38fec1c72878816bb8cc20d63a4dea6a4ca3 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Thu, 23 Jul 2015 14:57:04 -0700 Subject: [PATCH] Fix compiler type warnings. (closes #3765) The output of mutt_local_tz() was being passed to abs(). Technically the return type is time_t, but it represents a small value: the timezone offset in seconds. Add a safe explicit cast to int. Change the txt parameter of mutt_make_help() to type const char *. Typically all calls run the txt parameter through _(), which accepts const char * and returns a char *. However, if NLS is not enabled, _() is a noop, simply returning the parameter itself. In mutt_compile_help(), items[i].name is const char *, so it will generate a warning when passed as the txt parameter of mutt_make_help(). On some systems, e.g. OS X, snprintf is defined as a macro. One call in hcache.c was embedding directives inside the snprintf call. This is apparently undefined behavior, so duplicate the call instead. --- hcache.c | 20 ++++++++++++++++---- help.c | 2 +- imap/util.c | 2 +- protos.h | 2 +- sendlib.c | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/hcache.c b/hcache.c index 51f2f1a8..561dce3a 100644 --- a/hcache.c +++ b/hcache.c @@ -550,21 +550,33 @@ mutt_hcache_per_folder(const char *path, const char *folder, { md5_buffer (folder, strlen (folder), &md5sum); + /* On some systems (e.g. OS X), snprintf is defined as a macro. + * Embedding directives inside macros is undefined, so we have to duplicate + * the whole call: + */ +#ifndef HAVE_ICONV ret = snprintf(hcpath, _POSIX_PATH_MAX, "%s/%02x%02x%02x%02x%02x%02x%02x%02x" "%02x%02x%02x%02x%02x%02x%02x%02x" -#ifndef HAVE_ICONV "-%s" -#endif , path, md5sum[0], md5sum[1], md5sum[2], md5sum[3], md5sum[4], md5sum[5], md5sum[6], md5sum[7], md5sum[8], md5sum[9], md5sum[10], md5sum[11], md5sum[12], md5sum[13], md5sum[14], md5sum[15] -#ifndef HAVE_ICONV ,chs -#endif ); +#else + ret = snprintf(hcpath, _POSIX_PATH_MAX, + "%s/%02x%02x%02x%02x%02x%02x%02x%02x" + "%02x%02x%02x%02x%02x%02x%02x%02x" + , + path, md5sum[0], md5sum[1], md5sum[2], md5sum[3], + md5sum[4], md5sum[5], md5sum[6], md5sum[7], md5sum[8], + md5sum[9], md5sum[10], md5sum[11], md5sum[12], + md5sum[13], md5sum[14], md5sum[15] + ); +#endif } if (ret <= 0) diff --git a/help.c b/help.c index 8afabf03..c8042743 100644 --- a/help.c +++ b/help.c @@ -54,7 +54,7 @@ static const struct binding_t *help_lookupFunction (int op, int menu) return (NULL); } -void mutt_make_help (char *d, size_t dlen, char *txt, int menu, int op) +void mutt_make_help (char *d, size_t dlen, const char *txt, int menu, int op) { char buf[SHORT_STRING]; diff --git a/imap/util.c b/imap/util.c index 6295c5ff..c05465a3 100644 --- a/imap/util.c +++ b/imap/util.c @@ -591,7 +591,7 @@ void imap_make_date (char *buf, time_t timestamp) snprintf (buf, IMAP_DATELEN, "%02d-%s-%d %02d:%02d:%02d %+03d%02d", tm->tm_mday, Months[tm->tm_mon], tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec, - (int) tz / 60, (int) abs (tz) % 60); + (int) tz / 60, (int) abs ((int) tz) % 60); } /* imap_qualify_path: make an absolute IMAP folder target, given IMAP_MBOX diff --git a/protos.h b/protos.h index d232a4f6..fd898d6f 100644 --- a/protos.h +++ b/protos.h @@ -213,7 +213,7 @@ void mutt_draw_tree (CONTEXT *); void mutt_check_lookup_list (BODY *, char *, int); void mutt_make_attribution (CONTEXT *ctx, HEADER *cur, FILE *out); void mutt_make_forward_subject (ENVELOPE *env, CONTEXT *ctx, HEADER *cur); -void mutt_make_help (char *, size_t, char *, int, int); +void mutt_make_help (char *, size_t, const char *, int, int); void mutt_make_misc_reply_headers (ENVELOPE *env, CONTEXT *ctx, HEADER *cur, ENVELOPE *curenv); void mutt_make_post_indent (CONTEXT *ctx, HEADER *cur, FILE *out); void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra); diff --git a/sendlib.c b/sendlib.c index a3454163..a74874d1 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1486,7 +1486,7 @@ char *mutt_make_date (char *s, size_t len) snprintf (s, len, "Date: %s, %d %s %d %02d:%02d:%02d %+03d%02d\n", Weekdays[l->tm_wday], l->tm_mday, Months[l->tm_mon], l->tm_year + 1900, l->tm_hour, l->tm_min, l->tm_sec, - (int) tz / 60, (int) abs (tz) % 60); + (int) tz / 60, (int) abs ((int) tz) % 60); return (s); } -- 2.40.0