From 9b511b4e0f05b253324f9ffb672652936cfcd6bd Mon Sep 17 00:00:00 2001 From: Wei-keng Liao Date: Thu, 16 Nov 2017 00:01:01 -0600 Subject: [PATCH] fix codes might break strict-aliasing rules --- libsrc/ncx.m4 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libsrc/ncx.m4 b/libsrc/ncx.m4 index f28aa9a43..96ad9210b 100644 --- a/libsrc/ncx.m4 +++ b/libsrc/ncx.m4 @@ -461,10 +461,15 @@ swap8b(void *dst, const void *src) op = (uint32_t*)((char*)dst+4); *op = SWAP4(*op); #else + uint64_t tmp = *(uint64_t*)src; + tmp = SWAP8(tmp); + memcpy(dst, &tmp, 8); + + /* Codes below will cause "break strict-aliasing rules" in gcc uint64_t *op = (uint64_t*)dst; - /* copy over, make the below swap in-place */ *op = *(uint64_t*)src; *op = SWAP8(*op); + */ #endif #if 0