Thread (6 messages) 6 messages, 2 authors, 2012-12-11
STALE4973d

[PATCH 4/4] sdpd-request: Fix build errors due to unaligned memory access

From: Szymon Janc <hidden>
Date: 2012-11-23 10:09:14
Subsystem: the rest · Maintainer: Linus Torvalds

This fix following compilation errors on ARM.

  CC     src/bluetoothd-sdpd-request.o
src/sdpd-request.c: In function ‘extract_des’:
src/sdpd-request.c:186:17: error: cast increases required alignment of
	target type [-Werror=cast-align]
src/sdpd-request.c:186:17: error: cast increases required alignment of
	target type [-Werror=cast-align]
src/sdpd-request.c:210:17: error: cast increases required alignment of
	target type [-Werror=cast-align]
src/sdpd-request.c:210:17: error: cast increases required alignment of
	target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[1]: *** [src/bluetoothd-sdpd-request.o] Error 1
---
 src/sdpd-request.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index 2af743e..a79efc7 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -182,8 +182,12 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
 				aid->uint16 = bt_get_be16(p);
 				pElem = (char *) aid;
 			} else {
+				uint16_t tmp;
+
+				memcpy(&tmp, p, sizeof(tmp));
+
 				pElem = malloc(sizeof(uint16_t));
-				bt_put_be16(bt_get_unaligned((uint16_t *)p), pElem);
+				bt_put_be16(tmp, pElem);
 			}
 			p += sizeof(uint16_t);
 			seqlen += sizeof(uint16_t);
@@ -206,8 +210,12 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
 
 				pElem = (char *) aid;
 			} else {
+				uint32_t tmp;
+
+				memcpy(&tmp, p, sizeof(tmp));
+
 				pElem = malloc(sizeof(uint32_t));
-				bt_put_be32(bt_get_unaligned((uint32_t *)p), pElem);
+				bt_put_be32(tmp, pElem);
 			}
 			p += sizeof(uint32_t);
 			seqlen += sizeof(uint32_t);
-- 
1.7.9.5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help