When using the ZQ/ZZ keybindings we end up writing to a string literal
which results in a sigsegv. In order to avoid that we have to copy the
command name string.

Signed-off-by: Silvan Jegen <s.je...@gmail.com>
---
Heyhey

With this solution to the problem we end up copying all command names
which I do not like. A better approach would probably be to use function
pointer *func of struct KeyBinding for ZZ/ZQ to just exit the editor
(with or without saving) instead of using cmd -> exec_command ->
exec_cmdline_command.

What is the list's opinion on this?

Is there another, simpler way to work around this issue that I am
not seeing?


Cheers,

Silvan

 vis.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/vis.c b/vis.c
index 7dd6f06..f1a0d48 100644
--- a/vis.c
+++ b/vis.c
@@ -1774,7 +1774,8 @@ static bool exec_cmdline_command(char *line) {
        /* skip leading white space */
        while (*name == ' ')
                name++;
-       char *param = name;
+       char *nametosearch = strndup(name, 64);
+       char *param = nametosearch;
        while (*param && *param != ' ') {
                if (*param == '!') {
                        opt |= CMD_OPT_FORCE;
@@ -1785,9 +1786,10 @@ static bool exec_cmdline_command(char *line) {
        if (*param)
                *param++ = '\0'; /* truncate by overwriting ' ' or '!' */
 
-       Command *cmd = map_closest(cmdmap, name);
+       Command *cmd = map_closest(cmdmap, nametosearch);
        if (!cmd) {
                editor_info_show(vis, "Not an editor command");
+               free(nametosearch);
                return false;
        }
 
@@ -1817,6 +1819,7 @@ static bool exec_cmdline_command(char *line) {
        }
 
        cmd->cmd(&range, opt, argv);
+       free(nametosearch);
        return true;
 }
 
-- 
2.3.4


Reply via email to