From 38dff9a4391c3c3537814acecc88b433fcd40156 Mon Sep 17 00:00:00 2001 From: Juli Mallett Date: Fri, 3 May 2002 19:45:41 +0000 Subject: [PATCH] Fix a bug whereby we were getting ~0 and comparing it to maxsize, i.e. if s1 was 0 length, and replstr was 0 length, etc., we would end up subtracting one from zero and seeing if it was greater than the size_t (unsigned) var maxsize... This would cause us to return a string consisting of essentially only match, which is not the right behaviour if we have 0 length inpline. --- usr.bin/xargs/strnsubst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.bin/xargs/strnsubst.c b/usr.bin/xargs/strnsubst.c index 6baa3f0df70..5ca2773fded 100644 --- a/usr.bin/xargs/strnsubst.c +++ b/usr.bin/xargs/strnsubst.c @@ -48,7 +48,7 @@ strnsubst(char **str, const char *match, const char *replstr, size_t maxsize) if (this == NULL) break; if ((strlen(s2) + ((uintptr_t)this - (uintptr_t)s1) + - (strlen(replstr) - 1)) > maxsize) { + (strlen(replstr) - 1)) > maxsize && *replstr != '\0') { strlcat(s2, s1, maxsize); goto done; }