From a1d3ab05c45b7d32b9e00a45135c6c2c774c49a3 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 19 Nov 2016 09:57:14 -0500 Subject: [PATCH] kdc: start_kdc avoid warning The prior structure of the code was safe but can appear otherwise to static analyzers since the assignment to pids[i] occurs after exitting the for() loop. While here use calloc() instead of malloc()/memset(). Change-Id: I8455aa259fd8c7c17778827937ec26127fe0785c --- kdc/connect.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kdc/connect.c b/kdc/connect.c index 7af9c604e..73b338903 100644 --- a/kdc/connect.c +++ b/kdc/connect.c @@ -1116,10 +1116,9 @@ start_kdc(krb5_context context, if (max_kdcs < 1) max_kdcs = 1; - pids = malloc(max_kdcs * sizeof(*pids)); + pids = calloc(max_kdcs, sizeof(*pids)); if (!pids) krb5_err(context, 1, errno, "malloc"); - memset(pids, 0x0, max_kdcs * sizeof(*pids)); /* * We open a socketpair of which we hand one end to each of our kids. @@ -1190,10 +1189,12 @@ start_kdc(krb5_context context, sleep(10); break; default: - for (i=0; i < max_kdcs; i++) - if (pids[i] == 0) + for (i=0; i < max_kdcs; i++) { + if (pids[i] == 0) { + pids[i] = pid; break; - pids[i] = pid; + } + } kdc_log(context, config, 0, "KDC worker process started: %d", pid); num_kdcs++; gettimeofday(&tv1, NULL);