vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit d6a15127cafb906383f3e1251fe73352a065fee2
parent d2c3e179c320c8cd5465f6182e3d9f6bc38fbfc1
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 12 May 2020 09:08:04 +0200

vis: cleanup pre-processing of :-commands

Not sure why we need to allocate space for an additional character.
This also avoids creating out of bound pointers.

Diffstat:
Mvis.c | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/vis.c b/vis.c @@ -1946,14 +1946,14 @@ bool vis_cmd(Vis *vis, const char *cmdline) { return true; while (*cmdline == ':') cmdline++; - size_t len = strlen(cmdline); - char *line = malloc(len+2); + char *line = strdup(cmdline); if (!line) return false; - strncpy(line, cmdline, len+1); - for (char *end = line + len - 1; end >= line && isspace((unsigned char)*end); end--) - *end = '\0'; + size_t len = strlen(line); + while (len > 0 && isspace((unsigned char)line[len-1])) + len--; + line[len] = '\0'; enum SamError err = sam_cmd(vis, line); if (err != SAM_ERR_OK)