Correct incorrect type-punning fixes
authorAndrew Deason <adeason@sinenomine.net>
Thu, 1 Apr 2010 18:55:51 +0000 (13:55 -0500)
committerDerrick Brashear <shadow@dementia.org>
Fri, 9 Apr 2010 20:12:21 +0000 (13:12 -0700)
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 <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/rxdebug/rxdebug.c
src/util/uuid.c

index da5ffd6..86f105b 100644 (file)
@@ -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);
        }
     }
index b9af9fd..6238c9c 100644 (file)
@@ -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)