From dbee988e289081d0ee2f183b9e309c9bcfafb934 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Mon, 11 Jan 2010 15:18:50 +0100 Subject: [PATCH] Cast unaligned memcpy() args to char*, avoids over-optimization on ARM See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3934.html --- src/libstrongswan/utils.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h index 1ac16ec17..e744f39a5 100644 --- a/src/libstrongswan/utils.h +++ b/src/libstrongswan/utils.h @@ -349,8 +349,10 @@ bool return_false(); */ static inline void htoun16(void *network, u_int16_t host) { + char *unaligned = (char*)network; + host = htons(host); - memcpy(network, &host, sizeof(host)); + memcpy(unaligned, &host, sizeof(host)); } /** @@ -361,8 +363,10 @@ static inline void htoun16(void *network, u_int16_t host) */ static inline void htoun32(void *network, u_int32_t host) { + char *unaligned = (char*)network; + host = htonl(host); - memcpy(network, &host, sizeof(host)); + memcpy((char*)unaligned, &host, sizeof(host)); } /** @@ -373,9 +377,10 @@ static inline void htoun32(void *network, u_int32_t host) */ static inline u_int16_t untoh16(void *network) { + char *unaligned = (char*)network; u_int16_t tmp; - memcpy(&tmp, network, sizeof(tmp)); + memcpy(&tmp, unaligned, sizeof(tmp)); return ntohs(tmp); } @@ -387,9 +392,10 @@ static inline u_int16_t untoh16(void *network) */ static inline u_int32_t untoh32(void *network) { + char *unaligned = (char*)network; u_int32_t tmp; - memcpy(&tmp, network, sizeof(tmp)); + memcpy(&tmp, unaligned, sizeof(tmp)); return ntohl(tmp); }