Author: jilles
Date: Tue Jul  3 19:09:46 2018
New Revision: 335905
URL: https://svnweb.freebsd.org/changeset/base/335905

Log:
  rup: Fix -Wcast-align warnings
  
  Fix possible strict aliasing issue (if time_t is the same size as int but
  not int but for example long) which also resulted in a false positive
  warning on systems with 64-bit time_t. Pointer casts are bad; we can just
  copy the time_t.
  
  Elsewhere, avoid casting char * to int * by using memcpy().
  
  Reviewed by:  eadler
  Differential Revision:        https://reviews.freebsd.org/D16075

Modified:
  head/usr.bin/rup/Makefile
  head/usr.bin/rup/rup.c

Modified: head/usr.bin/rup/Makefile
==============================================================================
--- head/usr.bin/rup/Makefile   Tue Jul  3 18:45:04 2018        (r335904)
+++ head/usr.bin/rup/Makefile   Tue Jul  3 19:09:46 2018        (r335905)
@@ -4,6 +4,4 @@ PROG=   rup
 
 LIBADD=        rpcsvc
 
-NO_WCAST_ALIGN=        # Size is explicitly handled
-
 .include <bsd.prog.mk>

Modified: head/usr.bin/rup/rup.c
==============================================================================
--- head/usr.bin/rup/rup.c      Tue Jul  3 18:45:04 2018        (r335904)
+++ head/usr.bin/rup/rup.c      Tue Jul  3 19:09:46 2018        (r335905)
@@ -120,27 +120,16 @@ rstat_reply(statstime *host_stat, struct sockaddr_in *
 
        printf("%-*s\t", HOST_WIDTH, host);
 
-       if (sizeof(time_t) == sizeof(host_stat->curtime.tv_sec)) {
-               tmp_time = localtime((time_t *)&host_stat->curtime.tv_sec);
-               host_time = *tmp_time;
+       tmp_time_t = host_stat->curtime.tv_sec;
+       tmp_time = localtime(&tmp_time_t);
+       host_time = *tmp_time;
 
-               host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
+       host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
 
-               tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec);
-               host_uptime = *tmp_time;
-       }
-       else {                  /* non-32-bit time_t */
-               tmp_time_t = host_stat->curtime.tv_sec;
-               tmp_time = localtime(&tmp_time_t);
-               host_time = *tmp_time;
+       tmp_time_t = host_stat->curtime.tv_sec;
+       tmp_time = gmtime(&tmp_time_t);
+       host_uptime = *tmp_time;
 
-               host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
-
-               tmp_time_t = host_stat->curtime.tv_sec;
-               tmp_time = gmtime(&tmp_time_t);
-               host_uptime = *tmp_time;
-       }
-
        #define updays (host_stat->curtime.tv_sec  / 86400)
        if (host_uptime.tm_yday != 0)
                sprintf(days_buf, "%3d day%s, ", updays,
@@ -205,7 +194,7 @@ onehost(char *host)
                return(-1);
        }
 
-       addr.sin_addr.s_addr = *(int *)hp->h_addr;
+       memcpy(&addr.sin_addr.s_addr, hp->h_addr, sizeof(int));
        rstat_reply(&host_stat, &addr);
        clnt_destroy(rstat_clnt);
        return (0);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to