aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.pro>2026-06-02 13:05:35 +0300
committerhybrid <hybrid@hybridlabs.pro>2026-06-02 13:05:35 +0300
commit01ff62c0e497ab498351e1e1a1d8088aeb2130e3 (patch)
treef20c8ea13ea0390e3abc6d3f1327935dadee6bcb /src/main.c
parentc2ef4a1c93cd8a3e70eb4c7acb26f091545dba66 (diff)
downloadcgit_auth-01ff62c0e497ab498351e1e1a1d8088aeb2130e3.tar.gz
cgit_auth-01ff62c0e497ab498351e1e1a1d8088aeb2130e3.tar.bz2
cgit_auth-01ff62c0e497ab498351e1e1a1d8088aeb2130e3.zip
fix: malloc and space in tmp stringsyslog
Diffstat (limited to 'src/main.c')
-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);