diff options
| author | _ov4 <ov4@ov4.org> | 2026-09-15 01:41:50 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-09-15 01:41:50 +0000 |
| commit | af69219a7229ccf524987123b2ecd70ff0456c9f (patch) | |
| tree | 4482f81372d6c7dcca36da2c32f50b0bf43dde06 /src/parse.cc | |
| parent | 6088b661340f16f1c741190744578808d83b7716 (diff) | |
fix string constucting from nullptr
Diffstat (limited to 'src/parse.cc')
| -rw-r--r-- | src/parse.cc | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/parse.cc b/src/parse.cc index 8480811..f61913a 100644 --- a/src/parse.cc +++ b/src/parse.cc @@ -19,7 +19,16 @@ int parseline(const char *cmdline, char **argv) int bg; /* background job? */ strcpy(buf, cmdline); - buf[strlen(buf)-1] = ' '; /* replace trailing '\n' with space */ + if (buf[strlen(buf)-1] == '\n') + buf[strlen(buf)-1] = ' '; /* replace trailing '\n' with space */ + else + { + // if buffer is not large enough + // might be UB + // TODO: fix UB + buf[strlen(buf)] = ' '; + buf[strlen(buf)+1] = '\0'; + } while (*buf && (*buf == ' ')) /* ignore leading spaces */ buf++; |
