fix segfault when line only contains newline

This commit is contained in:
josch
2014-09-17 21:33:19 +02:00
parent ebedf596db
commit 2d6a79062a
2 changed files with 9 additions and 1 deletions

View File

@@ -134,6 +134,12 @@ _execute_shell_command(mfshell_t *mfshell,char *command)
// FIXME: handle non-zero return value of wordexp
retval = wordexp(command, &p, WRDE_SHOWERR | WRDE_UNDEF);
if (p.we_wordc < 1)
return 0;
if (p.we_wordv[0] == NULL)
return 0;
// TODO: handle retval
retval = _execute(mfshell, p.we_wordc, p.we_wordv);

4
main.c
View File

@@ -200,7 +200,9 @@ mfshell_run(mfshell_t *mfshell)
if (retval == -1) {
exit(1);
}
string_chomp(cmd);
if (cmd[strlen(cmd)-1] == '\n')
cmd[strlen(cmd)-1] = '\0';
printf("\n\r");