diff options
author | jmallett <jmallett@FreeBSD.org> | 2005-12-30 23:22:50 +0000 |
---|---|---|
committer | jmallett <jmallett@FreeBSD.org> | 2005-12-30 23:22:50 +0000 |
commit | 7618c13881f3aa701a1e45a69ca08b919426dba9 (patch) | |
tree | 6ea030ca4a6adeb54bde86405609d46111aeb75a /usr.bin/xargs | |
parent | 1a1e1570e1ec769808ffd99e879b7ac9f5d05332 (diff) | |
download | FreeBSD-src-7618c13881f3aa701a1e45a69ca08b919426dba9.zip FreeBSD-src-7618c13881f3aa701a1e45a69ca08b919426dba9.tar.gz |
Handle maxsize==0 in such a way that we don't modify the string.
Diffstat (limited to 'usr.bin/xargs')
-rw-r--r-- | usr.bin/xargs/strnsubst.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/usr.bin/xargs/strnsubst.c b/usr.bin/xargs/strnsubst.c index 82868ff..33366b6 100644 --- a/usr.bin/xargs/strnsubst.c +++ b/usr.bin/xargs/strnsubst.c @@ -36,6 +36,18 @@ strnsubst(char **str, const char *match, const char *replstr, size_t maxsize) s1 = *str; if (s1 == NULL) return; + /* + * If maxsize is 0 then set it to to the length of s1, because we have + * to duplicate s1. XXX we maybe should double-check whether the match + * appears in s1. If it doesn't, then we also have to set the length + * to the length of s1, to avoid modifying the argument. It may make + * sense to check if maxsize is <= strlen(s1), because in that case we + * want to return the unmodified string, too. + */ + if (maxsize == 0) { + match = NULL; + maxsize = strlen(s1) + 1; + } s2 = calloc(maxsize, 1); if (s2 == NULL) err(1, "calloc"); |