]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
net: fix net_reopen() initialization 153/head
authorSami Kerola <kerolasa@iki.fi>
Sun, 2 Oct 2016 21:17:39 +0000 (22:17 +0100)
committerSami Kerola <kerolasa@iki.fi>
Tue, 4 Oct 2016 10:33:51 +0000 (11:33 +0100)
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

diff --git a/net.c b/net.c
index ef12d063fab286e1aea83994d4c2525d57812f30..761b956915dc135d89af5697d26ceb849f2873ae 100644 (file)
--- 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));
   }