From 17bc11bd157db83fd90051824c289712fbac7eae Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 2 Jun 2019 07:10:15 +0000 Subject: [PATCH 1/3] yacc(1) copies its union so it is not a good place to store TAILQ_HEADs. Allocate them instead. Found from a problem reported by sthen@. --- cmd-parse.y | 263 ++++++++++++++++++++++++++++------------------------ 1 file changed, 140 insertions(+), 123 deletions(-) diff --git a/cmd-parse.y b/cmd-parse.y index 4d43789e..d369dc4e 100644 --- a/cmd-parse.y +++ b/cmd-parse.y @@ -64,7 +64,7 @@ struct cmd_parse_state { u_int escapes; char *error; - struct cmd_parse_commands commands; + struct cmd_parse_commands *commands; struct cmd_parse_scope *scope; TAILQ_HEAD(, cmd_parse_scope) stack; @@ -73,6 +73,7 @@ static struct cmd_parse_state parse_state; static char *cmd_parse_get_error(const char *, u_int, const char *); static void cmd_parse_free_command(struct cmd_parse_command *); +static struct cmd_parse_commands *cmd_parse_new_commands(void); static void cmd_parse_free_commands(struct cmd_parse_commands *); %} @@ -87,9 +88,9 @@ static void cmd_parse_free_commands(struct cmd_parse_commands *); int flag; struct { int flag; - struct cmd_parse_commands commands; + struct cmd_parse_commands *commands; } elif; - struct cmd_parse_commands commands; + struct cmd_parse_commands *commands; struct cmd_parse_command *command; } @@ -114,45 +115,46 @@ lines : /* empty */ { struct cmd_parse_state *ps = &parse_state; - TAILQ_CONCAT(&ps->commands, &$1, entry); + ps->commands = $1; } statements : statement '\n' { - TAILQ_INIT(&$$); - TAILQ_CONCAT(&$$, &$1, entry); + $$ = $1; } | statements statement '\n' { - TAILQ_INIT(&$$); - TAILQ_CONCAT(&$$, &$1, entry); - TAILQ_CONCAT(&$$, &$2, entry); + $$ = $1; + TAILQ_CONCAT($$, $2, entry); + free($2); } - statement : condition { struct cmd_parse_state *ps = &parse_state; - TAILQ_INIT(&$$); if (ps->scope == NULL || ps->scope->flag) - TAILQ_CONCAT(&$$, &$1, entry); - else - cmd_parse_free_commands(&$1); + $$ = $1; + else { + $$ = cmd_parse_new_commands(); + cmd_parse_free_commands($1); + } } | assignment { - TAILQ_INIT(&$$); + $$ = xmalloc (sizeof *$$); + TAILQ_INIT($$); } | commands { struct cmd_parse_state *ps = &parse_state; - TAILQ_INIT(&$$); if (ps->scope == NULL || ps->scope->flag) - TAILQ_CONCAT(&$$, &$1, entry); - else - cmd_parse_free_commands(&$1); + $$ = $1; + else { + $$ = cmd_parse_new_commands(); + cmd_parse_free_commands($1); + } } expanded : FORMAT @@ -242,117 +244,119 @@ if_close : ENDIF condition : if_open '\n' statements if_close { - TAILQ_INIT(&$$); if ($1) - TAILQ_CONCAT(&$$, &$3, entry); - else - cmd_parse_free_commands(&$3); + $$ = $3; + else { + $$ = cmd_parse_new_commands(); + cmd_parse_free_commands($3); + } } | if_open '\n' statements if_else '\n' statements if_close { - TAILQ_INIT(&$$); if ($1) { - TAILQ_CONCAT(&$$, &$3, entry); - cmd_parse_free_commands(&$6); + $$ = $3; + cmd_parse_free_commands($6); } else { - TAILQ_CONCAT(&$$, &$6, entry); - cmd_parse_free_commands(&$3); + $$ = $6; + cmd_parse_free_commands($3); } } | if_open '\n' statements elif if_close { - TAILQ_INIT(&$$); if ($1) { - TAILQ_CONCAT(&$$, &$3, entry); - cmd_parse_free_commands(&$4.commands); + $$ = $3; + cmd_parse_free_commands($4.commands); } else if ($4.flag) { - TAILQ_CONCAT(&$$, &$4.commands, entry); - cmd_parse_free_commands(&$3); + $$ = $4.commands; + cmd_parse_free_commands($3); } else { - cmd_parse_free_commands(&$3); - cmd_parse_free_commands(&$4.commands); + $$ = cmd_parse_new_commands(); + cmd_parse_free_commands($3); + cmd_parse_free_commands($4.commands); } } | if_open '\n' statements elif if_else '\n' statements if_close { - TAILQ_INIT(&$$); if ($1) { - TAILQ_CONCAT(&$$, &$3, entry); - cmd_parse_free_commands(&$4.commands); - cmd_parse_free_commands(&$7); + $$ = $3; + cmd_parse_free_commands($4.commands); + cmd_parse_free_commands($7); } else if ($4.flag) { - TAILQ_CONCAT(&$$, &$4.commands, entry); - cmd_parse_free_commands(&$3); - cmd_parse_free_commands(&$7); + $$ = $4.commands; + cmd_parse_free_commands($3); + cmd_parse_free_commands($7); } else { - TAILQ_CONCAT(&$$, &$7, entry); - cmd_parse_free_commands(&$3); - cmd_parse_free_commands(&$4.commands); + $$ = $7; + cmd_parse_free_commands($3); + cmd_parse_free_commands($4.commands); } } elif : if_elif '\n' statements { - TAILQ_INIT(&$$.commands); - if ($1) - TAILQ_CONCAT(&$$.commands, &$3, entry); - else - cmd_parse_free_commands(&$3); - $$.flag = $1; + if ($1) { + $$.flag = 1; + $$.commands = $3; + } else { + $$.flag = 0; + $$.commands = cmd_parse_new_commands(); + cmd_parse_free_commands($3); + } } | if_elif '\n' statements elif { - TAILQ_INIT(&$$.commands); if ($1) { $$.flag = 1; - TAILQ_CONCAT(&$$.commands, &$3, entry); - cmd_parse_free_commands(&$4.commands); + $$.commands = $3; + cmd_parse_free_commands($4.commands); + } else if ($4.flag) { + $$.flag = 1; + $$.commands = $4.commands; + cmd_parse_free_commands($3); } else { - $$.flag = $4.flag; - TAILQ_CONCAT(&$$.commands, &$4.commands, entry); - cmd_parse_free_commands(&$3); + $$.flag = 0; + $$.commands = cmd_parse_new_commands(); + cmd_parse_free_commands($3); + cmd_parse_free_commands($4.commands); } } - commands : command { struct cmd_parse_state *ps = &parse_state; - TAILQ_INIT(&$$); + $$ = cmd_parse_new_commands(); if (ps->scope == NULL || ps->scope->flag) - TAILQ_INSERT_TAIL(&$$, $1, entry); + TAILQ_INSERT_TAIL($$, $1, entry); else cmd_parse_free_command($1); } | commands ';' { - TAILQ_INIT(&$$); - TAILQ_CONCAT(&$$, &$1, entry); + $$ = $1; } | commands ';' condition1 { - TAILQ_INIT(&$$); - TAILQ_CONCAT(&$$, &$1, entry); - TAILQ_CONCAT(&$$, &$3, entry); + $$ = $1; + TAILQ_CONCAT($$, $3, entry); + free($3); } | commands ';' command { struct cmd_parse_state *ps = &parse_state; - TAILQ_INIT(&$$); if (ps->scope == NULL || ps->scope->flag) { - TAILQ_CONCAT(&$$, &$1, entry); - TAILQ_INSERT_TAIL(&$$, $3, entry); + $$ = $1; + TAILQ_INSERT_TAIL($$, $3, entry); } else { - cmd_parse_free_commands(&$1); + $$ = cmd_parse_new_commands(); + cmd_parse_free_commands($1); cmd_parse_free_command($3); } } | condition1 { - TAILQ_INIT(&$$); - TAILQ_CONCAT(&$$, &$1, entry); + $$ = $1; } command : assignment TOKEN @@ -378,76 +382,80 @@ command : assignment TOKEN condition1 : if_open commands if_close { - TAILQ_INIT(&$$); if ($1) - TAILQ_CONCAT(&$$, &$2, entry); - else - cmd_parse_free_commands(&$2); + $$ = $2; + else { + $$ = cmd_parse_new_commands(); + cmd_parse_free_commands($2); + } } | if_open commands if_else commands if_close { - TAILQ_INIT(&$$); if ($1) { - TAILQ_CONCAT(&$$, &$2, entry); - cmd_parse_free_commands(&$4); + $$ = $2; + cmd_parse_free_commands($4); } else { - TAILQ_CONCAT(&$$, &$4, entry); - cmd_parse_free_commands(&$2); + $$ = $4; + cmd_parse_free_commands($2); } } | if_open commands elif1 if_close { - TAILQ_INIT(&$$); if ($1) { - TAILQ_CONCAT(&$$, &$2, entry); - cmd_parse_free_commands(&$3.commands); + $$ = $2; + cmd_parse_free_commands($3.commands); } else if ($3.flag) { - TAILQ_CONCAT(&$$, &$3.commands, entry); - cmd_parse_free_commands(&$2); + $$ = $3.commands; + cmd_parse_free_commands($2); } else { - cmd_parse_free_commands(&$2); - cmd_parse_free_commands(&$3.commands); + $$ = cmd_parse_new_commands(); + cmd_parse_free_commands($2); + cmd_parse_free_commands($3.commands); } } | if_open commands elif1 if_else commands if_close { - TAILQ_INIT(&$$); if ($1) { - TAILQ_CONCAT(&$$, &$2, entry); - cmd_parse_free_commands(&$3.commands); - cmd_parse_free_commands(&$5); + $$ = $2; + cmd_parse_free_commands($3.commands); + cmd_parse_free_commands($5); } else if ($3.flag) { - TAILQ_CONCAT(&$$, &$3.commands, entry); - cmd_parse_free_commands(&$2); - cmd_parse_free_commands(&$5); + $$ = $3.commands; + cmd_parse_free_commands($2); + cmd_parse_free_commands($5); } else { - TAILQ_CONCAT(&$$, &$5, entry); - cmd_parse_free_commands(&$2); - cmd_parse_free_commands(&$3.commands); + $$ = $5; + cmd_parse_free_commands($2); + cmd_parse_free_commands($3.commands); } - } elif1 : if_elif commands { - TAILQ_INIT(&$$.commands); - if ($1) - TAILQ_CONCAT(&$$.commands, &$2, entry); - else - cmd_parse_free_commands(&$2); - $$.flag = $1; + if ($1) { + $$.flag = 1; + $$.commands = $2; + } else { + $$.flag = 0; + $$.commands = cmd_parse_new_commands(); + cmd_parse_free_commands($2); + } } | if_elif commands elif1 { - TAILQ_INIT(&$$.commands); if ($1) { $$.flag = 1; - TAILQ_CONCAT(&$$.commands, &$2, entry); - cmd_parse_free_commands(&$3.commands); + $$.commands = $2; + cmd_parse_free_commands($3.commands); + } else if ($3.flag) { + $$.flag = 1; + $$.commands = $3.commands; + cmd_parse_free_commands($2); } else { - $$.flag = $3.flag; - TAILQ_CONCAT(&$$.commands, &$3.commands, entry); - cmd_parse_free_commands(&$2); + $$.flag = 0; + $$.commands = cmd_parse_new_commands(); + cmd_parse_free_commands($2); + cmd_parse_free_commands($3.commands); } } @@ -496,6 +504,16 @@ cmd_parse_free_command(struct cmd_parse_command *cmd) free(cmd); } +static struct cmd_parse_commands * +cmd_parse_new_commands(void) +{ + struct cmd_parse_commands *cmds; + + cmds = xmalloc(sizeof *cmds); + TAILQ_INIT (cmds); + return (cmds); +} + static void cmd_parse_free_commands(struct cmd_parse_commands *cmds) { @@ -505,17 +523,17 @@ cmd_parse_free_commands(struct cmd_parse_commands *cmds) TAILQ_REMOVE(cmds, cmd, entry); cmd_parse_free_command(cmd); } + free(cmds); } static struct cmd_parse_commands * cmd_parse_run_parser(char **cause) { - struct cmd_parse_state *ps = &parse_state; - struct cmd_parse_commands *cmds; - struct cmd_parse_scope *scope, *scope1; - int retval; + struct cmd_parse_state *ps = &parse_state; + struct cmd_parse_scope *scope, *scope1; + int retval; - TAILQ_INIT(&ps->commands); + ps->commands = NULL; TAILQ_INIT(&ps->stack); retval = yyparse(); @@ -528,10 +546,9 @@ cmd_parse_run_parser(char **cause) return (NULL); } - cmds = xmalloc(sizeof *cmds); - TAILQ_INIT(cmds); - TAILQ_CONCAT(cmds, &ps->commands, entry); - return (cmds); + if (ps->commands == NULL) + return (cmd_parse_new_commands()); + return (ps->commands); } static struct cmd_parse_commands * @@ -573,7 +590,7 @@ cmd_parse_build_commands(struct cmd_parse_commands *cmds, /* Check for an empty list. */ if (TAILQ_EMPTY(cmds)) { - free(cmds); + cmd_parse_free_commands(cmds); pr.status = CMD_PARSE_EMPTY; return (&pr); } @@ -667,7 +684,6 @@ cmd_parse_build_commands(struct cmd_parse_commands *cmds, out: cmd_parse_free_commands(cmds); - free(cmds); return (&pr); } @@ -746,8 +762,7 @@ cmd_parse_from_arguments(int argc, char **argv, struct cmd_parse_input *pi) } cmd_log_argv(argc, argv, "%s", __func__); - cmds = xmalloc(sizeof *cmds); - TAILQ_INIT(cmds); + cmds = cmd_parse_new_commands(); copy = cmd_copy_argv(argc, argv); last = 0; @@ -800,6 +815,8 @@ cmd_parse_from_arguments(int argc, char **argv, struct cmd_parse_input *pi) TAILQ_INSERT_TAIL(cmds, cmd, entry); } } + + cmd_free_argv(argc, copy); return (cmd_parse_build_commands(cmds, pi)); } From e252984993fdfd57a1fdc1eaf393e42e8589d623 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 5 Jun 2019 06:44:08 +0100 Subject: [PATCH 2/3] If only one of -x or -y is given, use the calculated size for the other. Also fix some warnings. Pointed out by Ben Boeckel. --- cmd-new-session.c | 7 ++++++- cmd-parse.y | 1 + cmd-queue.c | 2 +- format.c | 4 +--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd-new-session.c b/cmd-new-session.c index 2fd13420..559c268c 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -242,8 +242,13 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) /* Create the new session. */ oo = options_create(global_s_options); - if (args_has(args, 'x') || args_has(args, 'y')) + if (args_has(args, 'x') || args_has(args, 'y')) { + if (!args_has(args, 'x')) + dsx = sx; + if (!args_has(args, 'y')) + dsy = sy; options_set_string(oo, "default-size", 0, "%ux%u", dsx, dsy); + } env = environ_create(); if (c != NULL && !args_has(args, 'E')) environ_update(global_s_options, c->environ, env); diff --git a/cmd-parse.y b/cmd-parse.y index d369dc4e..6feeb35a 100644 --- a/cmd-parse.y +++ b/cmd-parse.y @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/cmd-queue.c b/cmd-queue.c index 93dcaa53..1ee43508 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -202,7 +202,7 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current, { struct cmdq_item *item, *first = NULL, *last = NULL; struct cmd *cmd; - struct cmdq_shared *shared; + struct cmdq_shared *shared = NULL; u_int group = 0; TAILQ_FOREACH(cmd, &cmdlist->list, qentry) { diff --git a/format.c b/format.c index 45479d5e..5ca970b7 100644 --- a/format.c +++ b/format.c @@ -1518,7 +1518,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, char **buf, size_t *len, size_t *off) { struct window_pane *wp = ft->wp; - const char *errptr, *copy, *cp, *marker; + const char *errptr, *copy, *cp, *marker = NULL; char *copy0, *condition, *found, *new; char *value, *left, *right; size_t valuelen; @@ -1566,8 +1566,6 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, limit = 0; if (fm->argc == 2 && fm->argv[1] != NULL) marker = fm->argv[1]; - else - marker = NULL; break; case 'l': modifiers |= FORMAT_LITERAL; From 53914e50b90ddbe285c188c021c3922b4e4c9fb8 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 5 Jun 2019 15:09:42 +0100 Subject: [PATCH 3/3] RC2. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 2c1a8945..8ff6d16e 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # configure.ac -AC_INIT([tmux], 3.0-rc) +AC_INIT([tmux], 3.0-rc2) AC_PREREQ([2.60]) AC_CONFIG_AUX_DIR(etc)