aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 50beaaa..3f94e3b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#include <sys/syslog.h>
#include <syslog.h>
@@ -25,17 +26,17 @@ int main(int argc, char **argv) {
for (int i = 1; i < argc; i++) {
char *tmp = NULL;
- if ((tmp = malloc(strlen(argv[i]) + 4)) == NULL) {
+ if ((tmp = malloc(strlen(argv[i]) + sizeof(char) * (int)log10(i)))
+ == NULL) {
perror("main: malloc failed");
exit(EXIT_FAILURE);
}
- sprintf(tmp, "[%d] %s ", i, argv[i]);
+ sprintf(tmp, " [%d] %s", i, argv[i]);
strcat(str, tmp);
free(tmp);
}
- str[strlen(str)] = '\0';
syslog(LOG_DEBUG, "args: %s\n", str);