summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-12-16 12:10:35 +0100
committerTobias Klauser <tklauser@distanz.ch>2016-12-16 12:11:57 +0100
commit8642322396987a586037942a2e47dee44bb1ed05 (patch)
treea985f1490f39c8a1d8a599acb4a324fc2f4d4153
parent374141decf7c9978fd2c535099440d68e11e7683 (diff)
str: Avoid trailing space in string returng by argv2str()
Don't add a trailing whitespace to the string returned by argv2str(). Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-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