diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2020-05-12 09:08:04 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2020-05-12 09:20:00 +0200 |
| commit | 0314cb784e9e92c14fd832f9dd533f3c1a56394f (patch) | |
| tree | 41580d560fbf5a2c4db364733a5a17cce83a2697 | |
| parent | 95a41d7dac1a4f92fe6047eff0363b684e2bedc2 (diff) | |
| download | vis-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.
| -rw-r--r-- | vis.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -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) |
