aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-09-23 19:53:31 +0000
committerEric Andersen <andersen@codepoet.org>2000-09-23 19:53:31 +0000
commit96bdde97fb7ebb44a89404bb87dc8e8cd4ec7446 (patch)
tree0ca8189e67b96c03195193b6b2d060a8aa47b538
parent6d66817b6bcc237c24c6aeb37af1407b36f49f9f (diff)
downloadbusybox-96bdde97fb7ebb44a89404bb87dc8e8cd4ec7446.tar.gz
Fix memory problems, and make behavior correct.
-rw-r--r--findutils/xargs.c13
-rw-r--r--xargs.c13
2 files changed, 16 insertions, 10 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 24daf5085..bf68cf768 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -78,13 +78,16 @@ int xargs_main(int argc, char **argv)
/* Now, read in one line at a time from stdin, and run command+args on it */
in_from_stdin = get_line_from_file(stdin);
for (;in_from_stdin!=NULL;) {
+ char *tmp;
len = strlen(in_from_stdin) + len_args_from_cmdline;
- if ( len > len_cmd_to_be_executed ) {
- len_cmd_to_be_executed=len+3;
- cmd_to_be_executed=xrealloc(cmd_to_be_executed, len_cmd_to_be_executed);
- }
+ len_cmd_to_be_executed+=len+3;
+ cmd_to_be_executed=xrealloc(cmd_to_be_executed, len_cmd_to_be_executed);
+
+ /* Strip out any \n's, so we just get one command to run */
+ while( (tmp = strchr(in_from_stdin, '\n')) != NULL )
+ *tmp=' ';
+
strcat(cmd_to_be_executed, in_from_stdin);
- strcat(cmd_to_be_executed+strlen(cmd_to_be_executed)-2, " ");
strcat(cmd_to_be_executed, " ");
free(in_from_stdin);
diff --git a/xargs.c b/xargs.c
index 24daf5085..bf68cf768 100644
--- a/xargs.c
+++ b/xargs.c
@@ -78,13 +78,16 @@ int xargs_main(int argc, char **argv)
/* Now, read in one line at a time from stdin, and run command+args on it */
in_from_stdin = get_line_from_file(stdin);
for (;in_from_stdin!=NULL;) {
+ char *tmp;
len = strlen(in_from_stdin) + len_args_from_cmdline;
- if ( len > len_cmd_to_be_executed ) {
- len_cmd_to_be_executed=len+3;
- cmd_to_be_executed=xrealloc(cmd_to_be_executed, len_cmd_to_be_executed);
- }
+ len_cmd_to_be_executed+=len+3;
+ cmd_to_be_executed=xrealloc(cmd_to_be_executed, len_cmd_to_be_executed);
+
+ /* Strip out any \n's, so we just get one command to run */
+ while( (tmp = strchr(in_from_stdin, '\n')) != NULL )
+ *tmp=' ';
+
strcat(cmd_to_be_executed, in_from_stdin);
- strcat(cmd_to_be_executed+strlen(cmd_to_be_executed)-2, " ");
strcat(cmd_to_be_executed, " ");
free(in_from_stdin);