From 0f26c4742c11846908dbfa335116a51bb4e2614f Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Tue, 13 Aug 2019 18:49:19 +0200 Subject: [PATCH] Silence three GCC warnings. * In cmd-new-session.c, dsx and dxy "may be used uninitialized", and it was difficult to tell if that can happen in practice. * In format.c, strftime can do format checking if a string literal is given. * In options.c, pr "may be used uninitialized", though that can't happen in practice. The "diagnostic push/pop" pragma was added in GCC 4.6, and according to https://github.com/protocolbuffers/protobuf/issues/4156, there would be warnings if we used them for older GCCs. --- cmd-new-session.c | 6 +----- format.c | 7 +++++++ options.c | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd-new-session.c b/cmd-new-session.c index e054081539..af296dad93 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -76,7 +76,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) const char *errstr, *template, *group, *prefix, *tmp; char *cause, *cwd = NULL, *cp, *newname = NULL; int detached, already_attached, is_control = 0; - u_int sx, sy, dsx, dsy; + u_int sx, sy, dsx = 80, dsy = 24; struct spawn_context sc; enum cmd_retval retval; struct cmd_find_state fs; @@ -193,8 +193,6 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) if (strcmp(tmp, "-") == 0) { if (c != NULL) dsx = c->tty.sx; - else - dsx = 80; } else { dsx = strtonum(tmp, 1, USHRT_MAX, &errstr); if (errstr != NULL) { @@ -208,8 +206,6 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) if (strcmp(tmp, "-") == 0) { if (c != NULL) dsy = c->tty.sy; - else - dsy = 24; } else { dsy = strtonum(tmp, 1, USHRT_MAX, &errstr); if (errstr != NULL) { diff --git a/format.c b/format.c index eb7a9e53bc..821d956b62 100644 --- a/format.c +++ b/format.c @@ -1876,7 +1876,14 @@ format_expand1(struct format_tree *ft, const char *fmt, int time) if (time) { tm = localtime(&ft->time); +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif // __GNUC__ if (strftime(expanded, sizeof expanded, fmt, tm) == 0) { +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +# pragma GCC diagnostic pop +#endif // __GNUC__ format_log(ft, "format is too long"); return (xstrdup("")); } diff --git a/options.c b/options.c index 1be9f8cd75..d3a67d33aa 100644 --- a/options.c +++ b/options.c @@ -359,7 +359,7 @@ options_array_set(struct options_entry *o, u_int idx, const char *value, { struct options_array_item *a; char *new; - struct cmd_parse_result *pr; + struct cmd_parse_result *pr = NULL; if (!OPTIONS_IS_ARRAY(o)) { if (cause != NULL)