fssync-debug: fix strict-aliasing problems
authorAndrew Deason <adeason@sinenomine.net>
Thu, 1 Apr 2010 18:18:41 +0000 (13:18 -0500)
committerDerrick Brashear <shadow@dementia.org>
Thu, 1 Apr 2010 21:38:05 +0000 (14:38 -0700)
We cannot type-pun pointers like that. Instead, declare a new struct
on the stack, and copy the memory into it. Remove the CFLAGS_NOSTRICT
suppression on fssync-debug.o.

Change-Id: I25b48399417e009dc94bfebd513c0ee6feea282a
Reviewed-on: http://gerrit.openafs.org/1678
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/tsalvaged/Makefile.in
src/vol/Makefile.in
src/vol/fssync-debug.c

index c1ea332..464b6ce 100644 (file)
@@ -62,9 +62,8 @@ vol-salvage.o: ${VOL}/vol-salvage.c
 physio.o: ${VOL}/physio.c
        ${CCRULE}
 
-# Uses an alignment hack to convert between incompatible pointers.
 fssync-debug.o: ${VOL}/fssync-debug.c
-       $(CCOBJ) $(CFLAGS) @CFLAGS_NOSTRICT@ -c ${VOL}/fssync-debug.c
+       ${CCRULE}
 
 salvsync-debug.o: salvsync-debug.c
        ${CCRULE}
index a46f528..1afeabd 100644 (file)
@@ -225,10 +225,6 @@ volinfo: vol-info.o physio.o ihandle.o ${LIBS}
        ${CC} ${CFLAGS} -o volinfo vol-info.o physio.o \
                ihandle.o ${LIBS} ${XLIBS}
 
-# Uses an alignment hack to convert between incompatible pointers.
-fssync-debug.o: fssync-debug.c
-       $(CCOBJ) $(CFLAGS) @CFLAGS_NOSTRICT@ -c fssync-debug.c
-
 fssync-debug: fssync-debug.o physio.o AFS_component_version_number.c ${LIBS}
        ${CC} ${LDFLAGS} -o fssync-debug fssync-debug.o physio.o ${LIBS} ${XLIBS}
 
index 6571437..86b905f 100644 (file)
@@ -1061,17 +1061,7 @@ StatsQuery(struct cmd_syndesc * as, void * rock)
     SYNC_PROTO_BUF_DECL(res_buf);
     SYNC_response res;
     FSSYNC_StatsOp_hdr scom;
-    union {
-       void * ptr;
-       struct VolPkgStats * vol_stats;
-       struct VolumeHashChainStats * hash_stats;
-#ifdef AFS_DEMAND_ATTACH_FS
-       struct volume_hdr_LRU_stats * hdr_stats;
-#endif
-       struct DiskPartitionStats64 * vicep_stats;
-    } sres;
 
-    sres.ptr = res_buf;
     res.hdr.response_len = sizeof(res.hdr);
     res.payload.buf = res_buf;
     res.payload.len = SYNC_PROTO_MAX_LEN;
@@ -1158,18 +1148,34 @@ StatsQuery(struct cmd_syndesc * as, void * rock)
     if (res.hdr.response == SYNC_OK) {
        switch (command) {
        case FSYNC_VOL_STATS_GENERAL:
-           print_vol_stats_general(sres.vol_stats);
-           break;
+           {
+               struct VolPkgStats vol_stats;
+               memcpy(&vol_stats, res_buf, sizeof(vol_stats));
+               print_vol_stats_general(&vol_stats);
+               break;
+           }
        case FSYNC_VOL_STATS_VICEP:
-           print_vol_stats_viceP(sres.vicep_stats);
-           break;
+           {
+               struct DiskPartitionStats64 vicep_stats;
+               memcpy(&vicep_stats, res_buf, sizeof(vicep_stats));
+               print_vol_stats_viceP(&vicep_stats);
+               break;
+           }
        case FSYNC_VOL_STATS_HASH:
-           print_vol_stats_hash(sres.hash_stats);
-           break;
+           {
+               struct VolumeHashChainStats hash_stats;
+               memcpy(&hash_stats, res_buf, sizeof(hash_stats));
+               print_vol_stats_hash(&hash_stats);
+               break;
+           }
 #ifdef AFS_DEMAND_ATTACH_FS
        case FSYNC_VOL_STATS_HDR:
-           print_vol_stats_hdr(sres.hdr_stats);
-           break;
+           {
+               struct volume_hdr_LRU_stats hdr_stats;
+               memcpy(&hdr_stats, res_buf, sizeof(hdr_stats));
+               print_vol_stats_hdr(&hdr_stats);
+               break;
+           }
 #endif /* AFS_DEMAND_ATTACH_FS */
        }
     }