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:
parent
445577ce27
commit
da3d144a59
@ -4,6 +4,4 @@ PROG= rup
|
||||
|
||||
LIBADD= rpcsvc
|
||||
|
||||
NO_WCAST_ALIGN= # Size is explicitly handled
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -120,16 +120,6 @@ 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;
|
||||
|
||||
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;
|
||||
@ -139,7 +129,6 @@ rstat_reply(statstime *host_stat, struct sockaddr_in *raddrp)
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user