diff --git a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp index 8dffa8b4e20..91a9c6d0abf 100644 --- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp @@ -751,6 +751,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aMessage); + const uint8_t* data = aMessage->GetData(); int frameHeaderLength = 0; // See if this is the first part of each Put packet @@ -759,8 +760,9 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) // [opcode:1][length:2][Headers:var] frameHeaderLength = 3; - mPacketLength = ((((int)aMessage->mData[1]) << 8) | aMessage->mData[2]) - - frameHeaderLength; + mPacketLength = ((static_cast(data[1]) << 8) | data[2]) - + frameHeaderLength; + /** * A PUT request from remote devices may be divided into multiple parts. * In other words, one request may need to be received multiple times, @@ -771,7 +773,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal); } - int dataLength = aMessage->mSize - frameHeaderLength; + int dataLength = aMessage->GetSize() - frameHeaderLength; // Check length before memcpy to prevent from memory pollution if (dataLength < 0 || @@ -786,7 +788,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) } memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength, - &aMessage->mData[frameHeaderLength], dataLength); + &data[frameHeaderLength], dataLength); mPutPacketReceivedLength += dataLength; @@ -799,12 +801,13 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) MOZ_ASSERT(NS_IsMainThread()); uint8_t opCode; - int receivedLength = aMessage->mSize; + int receivedLength = aMessage->GetSize(); + const uint8_t* data = aMessage->GetData(); if (mPutPacketReceivedLength > 0) { opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put; } else { - opCode = aMessage->mData[0]; + opCode = data[0]; // When there's a Put packet right after a PutFinal packet, // which means it's the start point of a new file. @@ -821,7 +824,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) // Section 3.3.1 "Connect", IrOBEX 1.2 // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2] // [Headers:var] - if (!ParseHeaders(&aMessage->mData[7], receivedLength - 7, &pktHeaders)) { + if (!ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -831,7 +834,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) } else if (opCode == ObexRequestCode::Abort) { // Section 3.3.5 "Abort", IrOBEX 1.2 // [opcode:1][length:2][Headers:var] - if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { + if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -841,7 +844,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) } else if (opCode == ObexRequestCode::Disconnect) { // Section 3.3.2 "Disconnect", IrOBEX 1.2 // [opcode:1][length:2][Headers:var] - if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { + if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -924,7 +927,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage) { MOZ_ASSERT(NS_IsMainThread()); - uint8_t opCode = aMessage->mData[0]; + const uint8_t* data = aMessage->GetData(); + uint8_t opCode = data[0]; // Check response code and send out system message as finished if the response // code is somehow incorrect. @@ -981,10 +985,9 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage) AfterOppConnected(); // Keep remote information - mRemoteObexVersion = aMessage->mData[3]; - mRemoteConnectionFlags = aMessage->mData[4]; - mRemoteMaxPacketLength = - (((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]); + mRemoteObexVersion = data[3]; + mRemoteConnectionFlags = data[4]; + mRemoteMaxPacketLength = ((static_cast(data[5]) << 8) | data[6]); // The length of file name exceeds maximum length. int fileNameByteLen = (mFileName.Length() + 1) * 2; @@ -1253,8 +1256,7 @@ BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize) mLastCommand = aOpcode; } - UnixSocketRawData* s = new UnixSocketRawData(aSize); - memcpy(s->mData, aData, s->mSize); + UnixSocketRawData* s = new UnixSocketRawData(aData, aSize); mSocket->SendSocketData(s); } diff --git a/dom/bluetooth/bluez/BluetoothHfpManager.cpp b/dom/bluetooth/bluez/BluetoothHfpManager.cpp index 9922adedc62..0eebcebcbd9 100644 --- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluez/BluetoothHfpManager.cpp @@ -707,7 +707,8 @@ BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket, MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aSocket); - nsAutoCString msg((const char*)aMessage->mData.get(), aMessage->mSize); + nsAutoCString msg(reinterpret_cast(aMessage->GetData()), + aMessage->GetSize()); msg.StripWhitespace(); nsTArray atCommandValues; diff --git a/dom/bluetooth/bluez/BluetoothOppManager.cpp b/dom/bluetooth/bluez/BluetoothOppManager.cpp index e1e4449fd72..19bccd4423e 100644 --- a/dom/bluetooth/bluez/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluez/BluetoothOppManager.cpp @@ -774,6 +774,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) MOZ_ASSERT(aMessage); int frameHeaderLength = 0; + const uint8_t* data = aMessage->GetData(); // See if this is the first part of each Put packet if (mPutPacketReceivedLength == 0) { @@ -781,8 +782,8 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) // [opcode:1][length:2][Headers:var] frameHeaderLength = 3; - mPacketLength = ((((int)aMessage->mData[1]) << 8) | aMessage->mData[2]) - - frameHeaderLength; + mPacketLength = ((static_cast(data[1]) << 8) | data[2]) - + frameHeaderLength; /** * A PUT request from remote devices may be divided into multiple parts. * In other words, one request may need to be received multiple times, @@ -793,7 +794,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal); } - int dataLength = aMessage->mSize - frameHeaderLength; + int dataLength = aMessage->GetSize() - frameHeaderLength; // Check length before memcpy to prevent from memory pollution if (dataLength < 0 || @@ -808,7 +809,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) } memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength, - &aMessage->mData[frameHeaderLength], dataLength); + &data[frameHeaderLength], dataLength); mPutPacketReceivedLength += dataLength; @@ -821,12 +822,13 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) MOZ_ASSERT(NS_IsMainThread()); uint8_t opCode; - int receivedLength = aMessage->mSize; + int receivedLength = aMessage->GetSize(); + const uint8_t* data = aMessage->GetData(); if (mPutPacketReceivedLength > 0) { opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put; } else { - opCode = aMessage->mData[0]; + opCode = data[0]; // When there's a Put packet right after a PutFinal packet, // which means it's the start point of a new file. @@ -843,7 +845,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) // Section 3.3.1 "Connect", IrOBEX 1.2 // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2] // [Headers:var] - if (!ParseHeaders(&aMessage->mData[7], receivedLength - 7, &pktHeaders)) { + if (!ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -853,7 +855,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) } else if (opCode == ObexRequestCode::Abort) { // Section 3.3.5 "Abort", IrOBEX 1.2 // [opcode:1][length:2][Headers:var] - if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { + if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -863,7 +865,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) } else if (opCode == ObexRequestCode::Disconnect) { // Section 3.3.2 "Disconnect", IrOBEX 1.2 // [opcode:1][length:2][Headers:var] - if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { + if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -946,7 +948,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage) { MOZ_ASSERT(NS_IsMainThread()); - uint8_t opCode = aMessage->mData[0]; + const uint8_t* data = aMessage->GetData(); + uint8_t opCode = data[0]; // Check response code and send out system message as finished if the response // code is somehow incorrect. @@ -1003,10 +1006,9 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage) AfterOppConnected(); // Keep remote information - mRemoteObexVersion = aMessage->mData[3]; - mRemoteConnectionFlags = aMessage->mData[4]; - mRemoteMaxPacketLength = - (((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]); + mRemoteObexVersion = data[3]; + mRemoteConnectionFlags = data[4]; + mRemoteMaxPacketLength = (static_cast(data[5]) << 8) | data[6]; // The length of file name exceeds maximum length. int fileNameByteLen = (mFileName.Length() + 1) * 2; @@ -1274,8 +1276,7 @@ BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize) mLastCommand = aOpcode; } - UnixSocketRawData* s = new UnixSocketRawData(aSize); - memcpy(s->mData, aData, s->mSize); + UnixSocketRawData* s = new UnixSocketRawData(aData, aSize); mSocket->SendSocketData(s); } diff --git a/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp b/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp index 8dffa8b4e20..91a9c6d0abf 100644 --- a/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp +++ b/dom/bluetooth2/bluedroid/BluetoothOppManager.cpp @@ -751,6 +751,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aMessage); + const uint8_t* data = aMessage->GetData(); int frameHeaderLength = 0; // See if this is the first part of each Put packet @@ -759,8 +760,9 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) // [opcode:1][length:2][Headers:var] frameHeaderLength = 3; - mPacketLength = ((((int)aMessage->mData[1]) << 8) | aMessage->mData[2]) - - frameHeaderLength; + mPacketLength = ((static_cast(data[1]) << 8) | data[2]) - + frameHeaderLength; + /** * A PUT request from remote devices may be divided into multiple parts. * In other words, one request may need to be received multiple times, @@ -771,7 +773,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal); } - int dataLength = aMessage->mSize - frameHeaderLength; + int dataLength = aMessage->GetSize() - frameHeaderLength; // Check length before memcpy to prevent from memory pollution if (dataLength < 0 || @@ -786,7 +788,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) } memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength, - &aMessage->mData[frameHeaderLength], dataLength); + &data[frameHeaderLength], dataLength); mPutPacketReceivedLength += dataLength; @@ -799,12 +801,13 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) MOZ_ASSERT(NS_IsMainThread()); uint8_t opCode; - int receivedLength = aMessage->mSize; + int receivedLength = aMessage->GetSize(); + const uint8_t* data = aMessage->GetData(); if (mPutPacketReceivedLength > 0) { opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put; } else { - opCode = aMessage->mData[0]; + opCode = data[0]; // When there's a Put packet right after a PutFinal packet, // which means it's the start point of a new file. @@ -821,7 +824,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) // Section 3.3.1 "Connect", IrOBEX 1.2 // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2] // [Headers:var] - if (!ParseHeaders(&aMessage->mData[7], receivedLength - 7, &pktHeaders)) { + if (!ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -831,7 +834,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) } else if (opCode == ObexRequestCode::Abort) { // Section 3.3.5 "Abort", IrOBEX 1.2 // [opcode:1][length:2][Headers:var] - if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { + if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -841,7 +844,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) } else if (opCode == ObexRequestCode::Disconnect) { // Section 3.3.2 "Disconnect", IrOBEX 1.2 // [opcode:1][length:2][Headers:var] - if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { + if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -924,7 +927,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage) { MOZ_ASSERT(NS_IsMainThread()); - uint8_t opCode = aMessage->mData[0]; + const uint8_t* data = aMessage->GetData(); + uint8_t opCode = data[0]; // Check response code and send out system message as finished if the response // code is somehow incorrect. @@ -981,10 +985,9 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage) AfterOppConnected(); // Keep remote information - mRemoteObexVersion = aMessage->mData[3]; - mRemoteConnectionFlags = aMessage->mData[4]; - mRemoteMaxPacketLength = - (((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]); + mRemoteObexVersion = data[3]; + mRemoteConnectionFlags = data[4]; + mRemoteMaxPacketLength = ((static_cast(data[5]) << 8) | data[6]); // The length of file name exceeds maximum length. int fileNameByteLen = (mFileName.Length() + 1) * 2; @@ -1253,8 +1256,7 @@ BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize) mLastCommand = aOpcode; } - UnixSocketRawData* s = new UnixSocketRawData(aSize); - memcpy(s->mData, aData, s->mSize); + UnixSocketRawData* s = new UnixSocketRawData(aData, aSize); mSocket->SendSocketData(s); } diff --git a/dom/bluetooth2/bluez/BluetoothHfpManager.cpp b/dom/bluetooth2/bluez/BluetoothHfpManager.cpp index ffa1af38e47..cd9d4f9044e 100644 --- a/dom/bluetooth2/bluez/BluetoothHfpManager.cpp +++ b/dom/bluetooth2/bluez/BluetoothHfpManager.cpp @@ -707,7 +707,8 @@ BluetoothHfpManager::ReceiveSocketData(BluetoothSocket* aSocket, MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aSocket); - nsAutoCString msg((const char*)aMessage->mData.get(), aMessage->mSize); + nsAutoCString msg(reinterpret_cast(aMessage->GetData()), + aMessage->GetSize()); msg.StripWhitespace(); nsTArray atCommandValues; diff --git a/dom/bluetooth2/bluez/BluetoothOppManager.cpp b/dom/bluetooth2/bluez/BluetoothOppManager.cpp index e1e4449fd72..19bccd4423e 100644 --- a/dom/bluetooth2/bluez/BluetoothOppManager.cpp +++ b/dom/bluetooth2/bluez/BluetoothOppManager.cpp @@ -774,6 +774,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) MOZ_ASSERT(aMessage); int frameHeaderLength = 0; + const uint8_t* data = aMessage->GetData(); // See if this is the first part of each Put packet if (mPutPacketReceivedLength == 0) { @@ -781,8 +782,8 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) // [opcode:1][length:2][Headers:var] frameHeaderLength = 3; - mPacketLength = ((((int)aMessage->mData[1]) << 8) | aMessage->mData[2]) - - frameHeaderLength; + mPacketLength = ((static_cast(data[1]) << 8) | data[2]) - + frameHeaderLength; /** * A PUT request from remote devices may be divided into multiple parts. * In other words, one request may need to be received multiple times, @@ -793,7 +794,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) mPutFinalFlag = (aOpCode == ObexRequestCode::PutFinal); } - int dataLength = aMessage->mSize - frameHeaderLength; + int dataLength = aMessage->GetSize() - frameHeaderLength; // Check length before memcpy to prevent from memory pollution if (dataLength < 0 || @@ -808,7 +809,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketRawData* aMessage) } memcpy(mReceivedDataBuffer.get() + mPutPacketReceivedLength, - &aMessage->mData[frameHeaderLength], dataLength); + &data[frameHeaderLength], dataLength); mPutPacketReceivedLength += dataLength; @@ -821,12 +822,13 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) MOZ_ASSERT(NS_IsMainThread()); uint8_t opCode; - int receivedLength = aMessage->mSize; + int receivedLength = aMessage->GetSize(); + const uint8_t* data = aMessage->GetData(); if (mPutPacketReceivedLength > 0) { opCode = mPutFinalFlag ? ObexRequestCode::PutFinal : ObexRequestCode::Put; } else { - opCode = aMessage->mData[0]; + opCode = data[0]; // When there's a Put packet right after a PutFinal packet, // which means it's the start point of a new file. @@ -843,7 +845,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) // Section 3.3.1 "Connect", IrOBEX 1.2 // [opcode:1][length:2][version:1][flags:1][MaxPktSizeWeCanReceive:2] // [Headers:var] - if (!ParseHeaders(&aMessage->mData[7], receivedLength - 7, &pktHeaders)) { + if (!ParseHeaders(&data[7], receivedLength - 7, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -853,7 +855,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) } else if (opCode == ObexRequestCode::Abort) { // Section 3.3.5 "Abort", IrOBEX 1.2 // [opcode:1][length:2][Headers:var] - if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { + if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -863,7 +865,7 @@ BluetoothOppManager::ServerDataHandler(UnixSocketRawData* aMessage) } else if (opCode == ObexRequestCode::Disconnect) { // Section 3.3.2 "Disconnect", IrOBEX 1.2 // [opcode:1][length:2][Headers:var] - if (!ParseHeaders(&aMessage->mData[3], receivedLength - 3, &pktHeaders)) { + if (!ParseHeaders(&data[3], receivedLength - 3, &pktHeaders)) { ReplyError(ObexResponseCode::BadRequest); return; } @@ -946,7 +948,8 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage) { MOZ_ASSERT(NS_IsMainThread()); - uint8_t opCode = aMessage->mData[0]; + const uint8_t* data = aMessage->GetData(); + uint8_t opCode = data[0]; // Check response code and send out system message as finished if the response // code is somehow incorrect. @@ -1003,10 +1006,9 @@ BluetoothOppManager::ClientDataHandler(UnixSocketRawData* aMessage) AfterOppConnected(); // Keep remote information - mRemoteObexVersion = aMessage->mData[3]; - mRemoteConnectionFlags = aMessage->mData[4]; - mRemoteMaxPacketLength = - (((int)(aMessage->mData[5]) << 8) | aMessage->mData[6]); + mRemoteObexVersion = data[3]; + mRemoteConnectionFlags = data[4]; + mRemoteMaxPacketLength = (static_cast(data[5]) << 8) | data[6]; // The length of file name exceeds maximum length. int fileNameByteLen = (mFileName.Length() + 1) * 2; @@ -1274,8 +1276,7 @@ BluetoothOppManager::SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize) mLastCommand = aOpcode; } - UnixSocketRawData* s = new UnixSocketRawData(aSize); - memcpy(s->mData, aData, s->mSize); + UnixSocketRawData* s = new UnixSocketRawData(aData, aSize); mSocket->SendSocketData(s); }