From 772afcec1f9d6c8d9790e0346d8b792df6735bb3 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 2 Oct 2016 22:17:39 +0100 Subject: [PATCH] net: fix net_reopen() initialization Mantas Mikulenas reviewed recent pull reques that contained commit b90a522f23167bd00062504803e94220937aba23 making a code path quicker. Unfortunately initialization was incomplete, as demonstrated by R.E. Wolff in same review. Fix is to use GCC designated initializer. Reference: https://github.com/traviscross/mtr/pull/151 Reference: https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html Review update. Replace following initializer with an iterative loop. .saved = { [0 ... SAVED_PINGS - 1] = -2 }, This is done to keep compatibility with non-gcc compilers. Reference: https://github.com/traviscross/mtr/pull/153 --- net.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net.c b/net.c index ef12d06..761b956 100644 --- a/net.c +++ b/net.c @@ -1492,17 +1492,18 @@ extern void net_reopen(struct mtr_ctl *ctl, struct hostent * addr) extern void net_reset(struct mtr_ctl *ctl) { - static const struct nethost template = { - .saved = { -2 }, - .saved_seq_offset = 2 - SAVED_PINGS, - .xmit = 0 + static struct nethost template = { + .saved_seq_offset = 2 - SAVED_PINGS }; - int at; + int at, i; batch_at = ctl->fstTTL - 1; /* above replacedByMin */ numhosts = 10; + for (i = 0; i < SAVED_PINGS; i++) + template.saved[i] = -2; + for (at = 0; at < MaxHost; at++) { memcpy(&(host[at]), &template, sizeof(template)); } -- 2.47.2