diff options
| author | hybrid <hybrid@hybridlabs.pro> | 2026-06-02 13:05:35 +0300 |
|---|---|---|
| committer | hybrid <hybrid@hybridlabs.pro> | 2026-06-02 13:05:35 +0300 |
| commit | 01ff62c0e497ab498351e1e1a1d8088aeb2130e3 (patch) | |
| tree | f20c8ea13ea0390e3abc6d3f1327935dadee6bcb /src | |
| parent | c2ef4a1c93cd8a3e70eb4c7acb26f091545dba66 (diff) | |
| download | cgit_auth-syslog.tar.gz cgit_auth-syslog.tar.bz2 cgit_auth-syslog.zip | |
fix: malloc and space in tmp stringsyslog
Diffstat (limited to '')
| -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); |
