From 0314cb784e9e92c14fd832f9dd533f3c1a56394f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 12 May 2020 09:08:04 +0200 Subject: 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. --- vis.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'vis.c') diff --git a/vis.c b/vis.c index 768c3cb..15011dc 100644 --- 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) -- cgit v1.2.3