From 185a6a474ccaf15c1abb708bcdfe27857454cef4 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Thu, 1 Apr 2010 13:55:51 -0500 Subject: [PATCH] Correct incorrect type-punning fixes Commit 549002c906795f978eebf81c706995116a04a8ff attempted to resolve a few type-punning-related warnings, but did so using unions. Unions are not guaranteed to work correctly with type-punning on non-gcc, so partially revert and reimplement. Change-Id: I6a49184284809c929bc45b5de5b32b8323467505 Reviewed-on: http://gerrit.openafs.org/1679 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/rxdebug/rxdebug.c | 15 +++++++-------- src/util/uuid.c | 18 ++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/rxdebug/rxdebug.c b/src/rxdebug/rxdebug.c index da5ffd6..86f105b 100644 --- a/src/rxdebug/rxdebug.c +++ b/src/rxdebug/rxdebug.c @@ -278,21 +278,20 @@ MainCommand(struct cmd_syndesc *as, void *arock) fprintf(stderr, "WARNING: Server doesn't support retrieval of Rx statistics\n"); } else { - union { - struct rx_statistics rxstats; - struct rx_debugIn debug; - } packet; + struct rx_statistics rxstats; /* should gracefully handle the case where rx_stats grows */ code = - rx_GetServerStats(s, host, port, &packet.rxstats, + rx_GetServerStats(s, host, port, &rxstats, &supportedStatValues); if (code < 0) { printf("rxstats call failed with code %d\n", code); exit(1); } - if (code != sizeof(packet.rxstats)) { - if (packet.debug.type == RX_DEBUGI_BADTYPE) + if (code != sizeof(rxstats)) { + struct rx_debugIn debug; + memcpy(&debug, &rxstats, sizeof(debug)); + if (debug.type == RX_DEBUGI_BADTYPE) goto noRxStats; printf ("WARNING: returned Rx statistics of unexpected size (got %d)\n", @@ -300,7 +299,7 @@ MainCommand(struct cmd_syndesc *as, void *arock) /* handle other versions?... */ } - rx_PrintTheseStats(stdout, &packet.rxstats, sizeof(packet.rxstats), + rx_PrintTheseStats(stdout, &rxstats, sizeof(rxstats), tstats.nFreePackets, tstats.version); } } diff --git a/src/util/uuid.c b/src/util/uuid.c index b9af9fd..6238c9c 100644 --- a/src/util/uuid.c +++ b/src/util/uuid.c @@ -247,11 +247,8 @@ afs_uuid_create(afsUUID * uuid) afs_int32 got_no_time = 0, code; if (!uuid_init_done) { - union { - uuid_time_t t; - u_short seed[4]; - } uuid_time; - u_short seed = 0; + uuid_time_t t; + u_short seedp[4], seed = 0; rand_m = 971;; rand_ia = 11113; rand_ib = 104322; @@ -267,11 +264,12 @@ afs_uuid_create(afsUUID * uuid) * independent. Then for good measure to ensure a unique seed when there * are multiple processes creating UUID's on a system, we add in the PID. */ - uuid__get_os_time(&uuid_time.t); - seed ^= uuid_time.seed[0]; - seed ^= uuid_time.seed[1]; - seed ^= uuid_time.seed[2]; - seed ^= uuid_time.seed[3]; + uuid__get_os_time(&t); + memcpy(&seedp, &t, sizeof(seedp)); + seed ^= seedp[0]; + seed ^= seedp[1]; + seed ^= seedp[2]; + seed ^= seedp[3]; #if defined(KERNEL) && defined(AFS_XBSD_ENV) rand_irand += seed + (afs_uint32) curproc->p_pid; #elif defined(UKERNEL) -- 1.9.4