From 8844c339608d92c6a69364f84fcd14366cea9f13 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Thu, 1 Apr 2010 13:18:41 -0500 Subject: [PATCH] fssync-debug: fix strict-aliasing problems 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 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/tsalvaged/Makefile.in | 3 +-- src/vol/Makefile.in | 4 ---- src/vol/fssync-debug.c | 42 ++++++++++++++++++++++----------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/tsalvaged/Makefile.in b/src/tsalvaged/Makefile.in index c1ea33282..464b6ce08 100644 --- a/src/tsalvaged/Makefile.in +++ b/src/tsalvaged/Makefile.in @@ -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} diff --git a/src/vol/Makefile.in b/src/vol/Makefile.in index a46f528cf..1afeabd56 100644 --- a/src/vol/Makefile.in +++ b/src/vol/Makefile.in @@ -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} diff --git a/src/vol/fssync-debug.c b/src/vol/fssync-debug.c index 6571437b2..86b905f65 100644 --- a/src/vol/fssync-debug.c +++ b/src/vol/fssync-debug.c @@ -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 */ } } -- 2.39.5