From owner-svn-src-head@freebsd.org Tue Jul 3 19:09:47 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9E031103E9C2; Tue, 3 Jul 2018 19:09:47 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 45989929B8; Tue, 3 Jul 2018 19:09:47 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 266152031C; Tue, 3 Jul 2018 19:09:47 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w63J9lGH041709; Tue, 3 Jul 2018 19:09:47 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w63J9krp041707; Tue, 3 Jul 2018 19:09:46 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201807031909.w63J9krp041707@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Tue, 3 Jul 2018 19:09:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335905 - head/usr.bin/rup X-SVN-Group: head X-SVN-Commit-Author: jilles X-SVN-Commit-Paths: head/usr.bin/rup X-SVN-Commit-Revision: 335905 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jul 2018 19:09:47 -0000 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 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);