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 | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h
index 377ff45a..5f04316c 100644
--- a/lib/PublicInbox/xap_helper.h
+++ b/lib/PublicInbox/xap_helper.h
@@ -35,7 +35,10 @@
 #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;

Reply via email to