From 2abfb5a88b24546eb481129fd8532b0aabb8e581 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 21 Mar 2012 17:20:07 +0100 Subject: [PATCH] =?UTF-8?q?Bugfix:=20Also=20clear=20the=20command=20parser?= =?UTF-8?q?=E2=80=99s=20stack=20upon=20invalid=20commands=20(Thanks=20helg?= =?UTF-8?q?ikrs)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: #652 --- src/commands_parser.c | 5 ++++- testcases/t/120-multiple-cmds.t | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/commands_parser.c b/src/commands_parser.c index f0459220..27a782a2 100644 --- a/src/commands_parser.c +++ b/src/commands_parser.c @@ -91,7 +91,9 @@ static void push_string(const char *identifier, char *str) { /* When we arrive here, the stack is full. This should not happen and * means there’s either a bug in this parser or the specification * contains a command with more than 10 identified tokens. */ - printf("argh! stack full\n"); + fprintf(stderr, "BUG: commands_parser stack full. This means either a bug " + "in the code, or a new command which contains more than " + "10 identified tokens.\n"); exit(1); } @@ -392,6 +394,7 @@ struct CommandResult *parse_command(const char *input) { free(position); free(errormessage); + clear_stack(); break; } } diff --git a/testcases/t/120-multiple-cmds.t b/testcases/t/120-multiple-cmds.t index 8cd17a8a..2d0ddcf4 100644 --- a/testcases/t/120-multiple-cmds.t +++ b/testcases/t/120-multiple-cmds.t @@ -54,4 +54,13 @@ ok(($unused ~~ @{get_workspace_names()}), 'workspace exists after moving'); # TODO: need a non-invasive command before implementing a test which uses ',' +################################################################################ +# regression test: 10 invalid commands should not crash i3 (10 is the stack +# depth) +################################################################################ + +cmd 'move gibberish' for (0 .. 10); + +does_i3_live; + done_testing;