aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2020-05-12 09:08:04 +0200
committerMarc André Tanner <mat@brain-dump.org>2020-05-12 09:20:00 +0200
commit0314cb784e9e92c14fd832f9dd533f3c1a56394f (patch)
tree41580d560fbf5a2c4db364733a5a17cce83a2697 /vis.c
parent95a41d7dac1a4f92fe6047eff0363b684e2bedc2 (diff)
downloadvis-0314cb784e9e92c14fd832f9dd533f3c1a56394f.tar.gz
vis-0314cb784e9e92c14fd832f9dd533f3c1a56394f.tar.xz
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 (limited to 'vis.c')
-rw-r--r--vis.c10
1 files changed, 5 insertions, 5 deletions
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)