From e745b5ef655c38c0501d9d5ea1e2fd869ce4f355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 19 Jan 2016 13:30:00 +0100 Subject: vis: improve :-command argument tokenizing Should now handle trailing white spaces. --- vis-cmds.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/vis-cmds.c b/vis-cmds.c index 22c81ce..03d3c87 100644 --- a/vis-cmds.c +++ b/vis-cmds.c @@ -1113,7 +1113,11 @@ bool vis_cmd(Vis *vis, const char *cmdline) { char *line = malloc(len+2); if (!line) return false; - line = strncpy(line, cmdline, len+1); + strncpy(line, cmdline, len+1); + + for (char *end = line + len - 1; end >= line && isspace((unsigned char)*end); end--) + *end = '\0'; + char *name = line; Filerange range = parse_range(vis->win, &name); @@ -1173,8 +1177,12 @@ bool vis_cmd(Vis *vis, const char *cmdline) { } s = NULL; } - if (s && (s = strchr(s, ' '))) - *s++ = '\0'; + if (s) { + while (*s && !isspace((unsigned char)*s)) + s++; + if (*s) + *s++ = '\0'; + } /* strip out a single '!' argument to make ":q !" work */ if (argv[i] && !strcmp(argv[i], "!")) { opt |= CMD_OPT_FORCE; -- cgit v1.2.3