Do not skip over the null terminator

This commit is contained in:
René Kijewski 2014-02-26 13:21:25 +01:00
parent 0eb7597ab1
commit 28c4ef45f7

View File

@ -94,13 +94,12 @@ static void handle_input_line(shell_t *shell, char *line)
/* first we need to calculate the number of arguments */
unsigned argc = 0;
char *pos;
for (pos = line; *pos; ++pos) {
if (*pos <= ' ') {
*pos = 0;
continue;
}
else if (*pos == '"') {
char *pos = line;
while (1) {
if (*pos > ' ') {
/* found an argument */
if (*pos == '"') {
/* it's an quoted argument */
do {
++pos;
if (!*pos) {
@ -114,6 +113,7 @@ static void handle_input_line(shell_t *shell, char *line)
}
}
else {
/* it's an unquoted argument */
do {
++pos;
if (*pos == '"') {
@ -122,10 +122,20 @@ static void handle_input_line(shell_t *shell, char *line)
}
} while (*pos > ' ');
}
/* count the number of arguments we got */
++argc;
*pos = 0;
}
/* zero out the current position (space or quotation mark) and advance */
if (*pos > 0) {
*pos = 0;
++pos;
}
else {
break;
}
}
if (!argc) {
return;
}