Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/ping avoid bogus uninitialized gcc warning



details:   https://anonhg.NetBSD.org/src/rev/0d319c185359
branches:  trunk
changeset: 790661:0d319c185359
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Oct 19 01:08:25 2013 +0000

description:
avoid bogus uninitialized gcc warning

diffstat:

 sbin/ping/ping.c |  25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diffs (55 lines):

diff -r 7c5bdf740bbb -r 0d319c185359 sbin/ping/ping.c
--- a/sbin/ping/ping.c  Sat Oct 19 00:57:41 2013 +0000
+++ b/sbin/ping/ping.c  Sat Oct 19 01:08:25 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ping.c,v 1.106 2013/03/06 11:33:08 yamt Exp $  */
+/*     $NetBSD: ping.c,v 1.107 2013/10/19 01:08:25 christos Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -58,7 +58,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ping.c,v 1.106 2013/03/06 11:33:08 yamt Exp $");
+__RCSID("$NetBSD: ping.c,v 1.107 2013/10/19 01:08:25 christos Exp $");
 #endif
 
 #include <stdio.h>
@@ -1011,7 +1011,6 @@
        icp = (struct icmp *)(buf + hlen);
        if (icp->icmp_type == ICMP_ECHOREPLY
            && icp->icmp_id == ident) {
-               struct timespec tv;
 
                if (icp->icmp_seq == htons((u_int16_t)(ntransmitted-1)))
                        lastrcvd = 1;
@@ -1019,16 +1018,20 @@
                if (first_rx.tv_sec == 0)
                        first_rx = last_rx;
                nreceived++;
-               if (pingflags & F_TIMING) {
-                       struct tv32 tv32;
+               if (pingflags & (F_TIMING|F_TIMING64)) {
+                       struct timespec tv;
+
+                       if (pingflags & F_TIMING) {
+                               struct tv32 tv32;
 
-                       (void) memcpy(&tv32, icp->icmp_data, sizeof(tv32));
-                       tv.tv_sec = (uint32_t)ntohl(tv32.tv32_sec);
-                       tv.tv_nsec = ntohl(tv32.tv32_usec) * 1000;
-               } else if (pingflags & F_TIMING64) 
-                       (void) memcpy(&tv, icp->icmp_data, sizeof(tv));
+                               (void)memcpy(&tv32, icp->icmp_data, sizeof(tv32));
+                               tv.tv_sec = (uint32_t)ntohl(tv32.tv32_sec);
+                               tv.tv_nsec = ntohl(tv32.tv32_usec) * 1000;
+                       } else if (pingflags & F_TIMING64) 
+                               (void)memcpy(&tv, icp->icmp_data, sizeof(tv));
+                       else
+                               memset(&tv, 0, sizeof(tv));     /* XXX: gcc */
 
-               if (pingflags & (F_TIMING|F_TIMING64)) {
                        triptime = diffsec(&last_rx, &tv);
                        tsum += triptime;
                        tsumsq += triptime * triptime;



Home | Main Index | Thread Index | Old Index