diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-03-10 07:12:12 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-03-10 07:12:12 +0000 |
commit | 1365bb786155439041b7777d31bcfadb5276e824 (patch) | |
tree | 8920760c17eff02678dc81ae6e29d6e108f1d86c | |
parent | 78f57460f2776aeddb584dd10923959f26863ea5 (diff) |
When using wordexp, only try to use the expand command
when something actually got expanded. Skip it otherwise.
-Erik
-rw-r--r-- | lash.c | 26 | ||||
-rw-r--r-- | sh.c | 26 | ||||
-rw-r--r-- | shell/lash.c | 26 |
3 files changed, 42 insertions, 36 deletions
@@ -941,20 +941,22 @@ static int expand_arguments(char *command) return FALSE; } - /* Convert from char** (one word per string) to a simple char*, - * but don't overflow command which is BUFSIZ in length */ - *command = '\0'; - while (i < expand_result.we_wordc && total_length < BUFSIZ) { - length=strlen(expand_result.we_wordv[i])+1; - if (BUFSIZ-total_length-length <= 0) { - error_msg(out_of_space); - return FALSE; + if (expand_result.we_wordc > 0) { + /* Convert from char** (one word per string) to a simple char*, + * but don't overflow command which is BUFSIZ in length */ + *command = '\0'; + while (i < expand_result.we_wordc && total_length < BUFSIZ) { + length=strlen(expand_result.we_wordv[i])+1; + if (BUFSIZ-total_length-length <= 0) { + error_msg(out_of_space); + return FALSE; + } + strcat(command+total_length, expand_result.we_wordv[i++]); + strcat(command+total_length, " "); + total_length+=length; } - strcat(command+total_length, expand_result.we_wordv[i++]); - strcat(command+total_length, " "); - total_length+=length; + wordfree (&expand_result); } - wordfree (&expand_result); #else /* Ok. They don't have a recent glibc and they don't have uClibc. Chances @@ -941,20 +941,22 @@ static int expand_arguments(char *command) return FALSE; } - /* Convert from char** (one word per string) to a simple char*, - * but don't overflow command which is BUFSIZ in length */ - *command = '\0'; - while (i < expand_result.we_wordc && total_length < BUFSIZ) { - length=strlen(expand_result.we_wordv[i])+1; - if (BUFSIZ-total_length-length <= 0) { - error_msg(out_of_space); - return FALSE; + if (expand_result.we_wordc > 0) { + /* Convert from char** (one word per string) to a simple char*, + * but don't overflow command which is BUFSIZ in length */ + *command = '\0'; + while (i < expand_result.we_wordc && total_length < BUFSIZ) { + length=strlen(expand_result.we_wordv[i])+1; + if (BUFSIZ-total_length-length <= 0) { + error_msg(out_of_space); + return FALSE; + } + strcat(command+total_length, expand_result.we_wordv[i++]); + strcat(command+total_length, " "); + total_length+=length; } - strcat(command+total_length, expand_result.we_wordv[i++]); - strcat(command+total_length, " "); - total_length+=length; + wordfree (&expand_result); } - wordfree (&expand_result); #else /* Ok. They don't have a recent glibc and they don't have uClibc. Chances diff --git a/shell/lash.c b/shell/lash.c index 8f19e526a..d321c929b 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -941,20 +941,22 @@ static int expand_arguments(char *command) return FALSE; } - /* Convert from char** (one word per string) to a simple char*, - * but don't overflow command which is BUFSIZ in length */ - *command = '\0'; - while (i < expand_result.we_wordc && total_length < BUFSIZ) { - length=strlen(expand_result.we_wordv[i])+1; - if (BUFSIZ-total_length-length <= 0) { - error_msg(out_of_space); - return FALSE; + if (expand_result.we_wordc > 0) { + /* Convert from char** (one word per string) to a simple char*, + * but don't overflow command which is BUFSIZ in length */ + *command = '\0'; + while (i < expand_result.we_wordc && total_length < BUFSIZ) { + length=strlen(expand_result.we_wordv[i])+1; + if (BUFSIZ-total_length-length <= 0) { + error_msg(out_of_space); + return FALSE; + } + strcat(command+total_length, expand_result.we_wordv[i++]); + strcat(command+total_length, " "); + total_length+=length; } - strcat(command+total_length, expand_result.we_wordv[i++]); - strcat(command+total_length, " "); - total_length+=length; + wordfree (&expand_result); } - wordfree (&expand_result); #else /* Ok. They don't have a recent glibc and they don't have uClibc. Chances |