OSDN Git Service

sdpd-request: Fix build errors due to unaligned memory access
authorSzymon Janc <szymon.janc@tieto.com>
Fri, 23 Nov 2012 10:09:14 +0000 (11:09 +0100)
committerJohan Hedberg <johan.hedberg@intel.com>
Tue, 11 Dec 2012 05:41:08 +0000 (07:41 +0200)
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

index 2af743e..a79efc7 100644 (file)
@@ -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);