1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-24 07:40:52 +00:00

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
This commit is contained in:
Jilles Tjoelker 2018-07-03 19:09:46 +00:00
parent d69d8a46cd
commit 8f8092f8e7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=335905
2 changed files with 8 additions and 21 deletions

View File

@ -4,6 +4,4 @@ PROG= rup
LIBADD= rpcsvc
NO_WCAST_ALIGN= # Size is explicitly handled
.include <bsd.prog.mk>

View File

@ -120,26 +120,15 @@ rstat_reply(statstime *host_stat, struct sockaddr_in *raddrp)
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;
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;
}
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)
@ -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);