summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--str.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/str.c b/str.c
index cfee03f..532058a 100644
--- a/str.c
+++ b/str.c
@@ -97,11 +97,13 @@ char *argv2str(int startind, int argc, char **argv)
int ret, i;
for (i = startind; i < argc; ++i) {
- size_t alen = strlen(argv[i]) + 2;
+ size_t tlen = (i < argc - 1) ? 2 : 1;
+ size_t alen = strlen(argv[i]) + tlen;
size_t slen = str ? strlen(str) : 0;
str = xrealloc(str, slen + alen);
- ret = slprintf(str + offset, strlen(argv[i]) + 2, "%s ", argv[i]);
+ ret = slprintf(str + offset, strlen(argv[i]) + tlen, "%s%s",
+ argv[i], tlen == 2 ? " " : "");
if (ret < 0)
panic("Cannot concatenate string!\n");
else