summaryrefslogtreecommitdiffstats
path: root/usr.bin/xargs
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2002-05-30 19:24:08 +0000
committerjmallett <jmallett@FreeBSD.org>2002-05-30 19:24:08 +0000
commita2f7c4e9ca9c5b8eb5cee77480f66ad591a851fa (patch)
treedf726809038b1efa6830d02f8e969569b2cba5a9 /usr.bin/xargs
parentd47e46d879b21734253820a147ffd6c989b353f8 (diff)
downloadFreeBSD-src-a2f7c4e9ca9c5b8eb5cee77480f66ad591a851fa.zip
FreeBSD-src-a2f7c4e9ca9c5b8eb5cee77480f66ad591a851fa.tar.gz
Allow the input line to be NULL, and teach strnsubst() that NULL means to use
a nil-string.
Diffstat (limited to 'usr.bin/xargs')
-rw-r--r--usr.bin/xargs/strnsubst.c5
-rw-r--r--usr.bin/xargs/xargs.c6
2 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/xargs/strnsubst.c b/usr.bin/xargs/strnsubst.c
index 5ca2773..b6668b7 100644
--- a/usr.bin/xargs/strnsubst.c
+++ b/usr.bin/xargs/strnsubst.c
@@ -24,6 +24,8 @@ void strnsubst(char **, const char *, const char *, size_t);
* maxsize bytes large. It does not free the string pointed to by str, it
* is up to the calling program to be sure that the original contents of
* str as well as the new contents are handled in an appropriate manner.
+ * If replstr is NULL, then that internally is changed to a nil-string, so
+ * that we can still pretend to do somewhat meaningful substitution.
* No value is returned.
*/
void
@@ -38,6 +40,9 @@ strnsubst(char **str, const char *match, const char *replstr, size_t maxsize)
if (s2 == NULL)
err(1, "calloc");
+ if (replstr == NULL)
+ replstr = "";
+
if (match == NULL || replstr == NULL || maxsize == strlen(s1)) {
strlcpy(s2, s1, maxsize);
goto done;
diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c
index e37a7e4..832e999 100644
--- a/usr.bin/xargs/xargs.c
+++ b/usr.bin/xargs/xargs.c
@@ -454,10 +454,10 @@ prerun(int argc, char **argv)
free(tmp2);
/*
- * Free the input line buffer, and create a new dummy.
+ * Free the input line buffer, if we have one.
*/
- free(inpline);
- inpline = strdup("");
+ if (inpline != NULL)
+ free(inpline);
}
static void
OpenPOWER on IntegriCloud