Skip to content

Commit

Permalink
[Coverity] Fix mediam and low impact issues
Browse files Browse the repository at this point in the history
Uninitialized and COPY_INSTED_OF_MOVE
issues are resolved in bluetooth interface

Tested:
BT on/off -> 20times
Connect phone, play music -> 10 times
HFP call -> 10 times
File transfer
CtsBluetoothTestCases

Tracked-On: OAM-123193
Signed-off-by: devath1x <[email protected]>
  • Loading branch information
devath1x committed Aug 23, 2024
1 parent becb3f5 commit b6203db
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bluetooth/bluetooth_hci.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BluetoothDeathRecipient : public hidl_death_recipient {
void setHasDied(bool has_died) { has_died_ = has_died; }

private:
bool has_died_;
bool has_died_=false/*has_died_ initializing with false*/;
};

BluetoothHci::BluetoothHci()
Expand Down
6 changes: 3 additions & 3 deletions bluetooth/h4_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class H4Protocol : public HciProtocol {
H4Protocol(int fd, PacketReadCallback event_cb, PacketReadCallback acl_cb,
PacketReadCallback sco_cb)
: uart_fd_(fd),
event_cb_(event_cb),
acl_cb_(acl_cb),
sco_cb_(sco_cb),
event_cb_(std::move(event_cb)),
acl_cb_(std::move(acl_cb)),
sco_cb_(std::move(sco_cb)),
hci_packetizer_([this]() { OnPacketReady(); }) {}

size_t Send(uint8_t type, const uint8_t* data, size_t length);
Expand Down
2 changes: 1 addition & 1 deletion bluetooth/hci_packetizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using HciPacketReadyCallback = std::function<void(void)>;
class HciPacketizer {
public:
HciPacketizer(HciPacketReadyCallback packet_cb)
: packet_ready_cb_(packet_cb){};
: packet_ready_cb_(std::move(packet_cb)){};
void OnDataReady(int fd, HciPacketType packet_type);
void CbHciPacket(uint8_t* data, size_t length);
const hidl_vec<uint8_t>& GetPacket() const;
Expand Down
4 changes: 2 additions & 2 deletions bluetooth/mct_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace hci {

MctProtocol::MctProtocol(int* fds, PacketReadCallback event_cb,
PacketReadCallback acl_cb)
: event_cb_(event_cb),
acl_cb_(acl_cb),
: event_cb_(std::move(event_cb)),
acl_cb_(std::move(acl_cb)),
event_packetizer_([this]() { OnEventPacketReady(); }),
acl_packetizer_([this]() { OnAclDataPacketReady(); }) {
for (int i = 0; i < CH_MAX; i++) {
Expand Down
12 changes: 6 additions & 6 deletions bluetooth/vendor_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ bool VendorInterface::Initialize(
return false;
}
g_vendor_interface = new VendorInterface();
return g_vendor_interface->Open(initialize_complete_cb, event_cb, acl_cb,
sco_cb);
return g_vendor_interface->Open(std::move(initialize_complete_cb), std::move(event_cb), std::move(acl_cb),
std::move(sco_cb));
}

void VendorInterface::Shutdown() {
Expand All @@ -192,7 +192,7 @@ bool VendorInterface::Open(InitializeCompleteCallback initialize_complete_cb,
PacketReadCallback event_cb,
PacketReadCallback acl_cb,
PacketReadCallback sco_cb) {
initialize_complete_cb_ = initialize_complete_cb;
initialize_complete_cb_ = std::move(initialize_complete_cb);

// Initialize vendor interface

Expand Down Expand Up @@ -247,20 +247,20 @@ bool VendorInterface::Open(InitializeCompleteCallback initialize_complete_cb,
}
}

event_cb_ = event_cb;
event_cb_ = std::move(event_cb);
PacketReadCallback intercept_events = [this](const hidl_vec<uint8_t>& event) {
HandleIncomingEvent(event);
};

if (fd_count == 1) {
hci::H4Protocol* h4_hci =
new hci::H4Protocol(fd_list[0], intercept_events, acl_cb, sco_cb);
new hci::H4Protocol(fd_list[0], intercept_events, acl_cb, std::move(sco_cb));
fd_watcher_.WatchFdForNonBlockingReads(
fd_list[0], [h4_hci](int fd) { h4_hci->OnDataReady(fd); });
hci_ = h4_hci;
} else {
hci::MctProtocol* mct_hci =
new hci::MctProtocol(fd_list, intercept_events, acl_cb);
new hci::MctProtocol(fd_list, std::move(intercept_events), acl_cb);
fd_watcher_.WatchFdForNonBlockingReads(
fd_list[CH_EVT], [mct_hci](int fd) { mct_hci->OnEventDataReady(fd); });
fd_watcher_.WatchFdForNonBlockingReads(
Expand Down

0 comments on commit b6203db

Please sign in to comment.