summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2002-04-13 10:13:39 +0000
committerobrien <obrien@FreeBSD.org>2002-04-13 10:13:39 +0000
commite2a368995a1373f9bd14d34997f119346f009a72 (patch)
tree17d331f269835e3278dfd0407335ffb9d519896a /usr.bin
parent64ca8195974724944e2d098ee0799ad511c8e949 (diff)
downloadFreeBSD-src-e2a368995a1373f9bd14d34997f119346f009a72.zip
FreeBSD-src-e2a368995a1373f9bd14d34997f119346f009a72.tar.gz
Make str_concat handle NULL arguments properly (a-la how ODE-2.3.6 make does).
Submitted by: jmallett Inspired by: CMU BUILDTOOLS4 coredumping, ODE-2.3.6 make(1)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/make/str.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/usr.bin/make/str.c b/usr.bin/make/str.c
index d4f84ea..ad7f864 100644
--- a/usr.bin/make/str.c
+++ b/usr.bin/make/str.c
@@ -96,31 +96,32 @@ str_concat(s1, s2, flags)
char *result;
/* get the length of both strings */
- len1 = strlen(s1);
- len2 = strlen(s2);
+ len1 = s1 == NULL ? 0 : strlen(s1);
+ len2 = s2 == NULL ? 0 : strlen(s2);
/* allocate length plus separator plus EOS */
result = emalloc((u_int)(len1 + len2 + 2));
/* copy first string into place */
- memcpy(result, s1, len1);
+ if (len1)
+ memcpy(result, s1, len1);
/* add separator character */
- if (flags & STR_ADDSPACE) {
- result[len1] = ' ';
- ++len1;
- } else if (flags & STR_ADDSLASH) {
- result[len1] = '/';
- ++len1;
+ if (len1 && len2) {
+ if (flags & STR_ADDSPACE)
+ result[len1++] = ' ';
+ else if (flags & STR_ADDSLASH)
+ result[len1++] = '/';
}
/* copy second string plus EOS into place */
- memcpy(result + len1, s2, len2 + 1);
+ if (len2)
+ memcpy(result + len1, s2, len2 + 1);
/* free original strings */
if (flags & STR_DOFREE) {
- (void)free(__DECONST(void *, s1));
- (void)free(__DECONST(void *, s2));
+ (void)efree(__DECONST(void *, s1));
+ (void)efree(__DECONST(void *, s2));
}
return(result);
}
OpenPOWER on IntegriCloud