]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
xap_helper.h: add missing headers and avoid reallocarray
authorEric Wong <e@80x24.org>
Sun, 24 Sep 2023 21:08:22 +0000 (21:08 +0000)
committerEric Wong <e@80x24.org>
Sun, 24 Sep 2023 23:14:24 +0000 (23:14 +0000)
These changes are necessary with glibc 2.17 and g++ 4.8.5
on CentOS 7.x.  We don't have to worry about overflow with
realloc(3) here since WORKER_MAX is only USHRT_MAX and
sizeof(pid_t) is 4 bytes on every platform I've encountered.

lib/PublicInbox/xap_helper.h

index 377ff45ae08657e72ae53e902a4c5afcf13e3334..5f04316c9cee0e720663fc40cf02bb3759523abb 100644 (file)
 #include <limits.h>
 #include <search.h>
 #include <signal.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sysexits.h>
 #include <unistd.h>
@@ -1084,9 +1087,9 @@ static void do_sigttin(void)
                warnx("workers cannot exceed %zu", (size_t)WORKER_MAX);
                return;
        }
-       void *p = reallocarray(worker_pids, nworker + 1, sizeof(pid_t));
+       void *p = realloc(worker_pids, (nworker + 1) * sizeof(pid_t));
        if (!p) {
-               warn("reallocarray");
+               warn("realloc worker_pids");
        } else {
                worker_pids = (pid_t *)p;
                worker_pids[nworker++] = 0;