Skip to content

Commit 9e523b5

Browse files
Merge pull request #370 from fabik111/fix-m0-handle-assignment
Arduino M0 board crashes when setting BLE handle from data buffer
2 parents baa1370 + eef16ce commit 9e523b5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/utility/ATT.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,8 @@ void ATTClass::readOrReadBlobReq(uint16_t connectionHandle, uint16_t mtu, uint8_
993993
}
994994
/// if auth error, hold the response in a buffer.
995995
bool holdResponse = false;
996-
997-
uint16_t handle = *(uint16_t*)data;
996+
uint16_t handle;
997+
memcpy(&handle, data, sizeof(handle));
998998
uint16_t offset = (opcode == ATT_OP_READ_REQ) ? 0 : *(uint16_t*)&data[sizeof(handle)];
999999

10001000
if ((uint16_t)(handle - 1) > GATT.attributeCount()) {
@@ -1248,7 +1248,8 @@ void ATTClass::writeReqOrCmd(uint16_t connectionHandle, uint16_t mtu, uint8_t op
12481248
return;
12491249
}
12501250

1251-
uint16_t handle = *(uint16_t*)data;
1251+
uint16_t handle;
1252+
memcpy(&handle, data, sizeof(handle));
12521253

12531254
if ((uint16_t)(handle - 1) > GATT.attributeCount()) {
12541255
if (withResponse) {

0 commit comments

Comments
 (0)