Skip to content

Commit

Permalink
Silence three GCC warnings.
Browse files Browse the repository at this point in the history
* 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 protocolbuffers/protobuf#4156, there
would be warnings if we used them for older GCCs.
  • Loading branch information
Tommie Gannert committed Aug 13, 2019
1 parent 9b3fefc commit 0f26c47
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 1 addition & 5 deletions cmd-new-session.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions format.c
Expand Up @@ -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(""));
}
Expand Down
2 changes: 1 addition & 1 deletion options.c
Expand Up @@ -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)
Expand Down

0 comments on commit 0f26c47

Please sign in to comment.