diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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); |
