From f337d7934f9f90e927b48fd0951b8d1be82cad8c Mon Sep 17 00:00:00 2001 From: Aleksejs Popovs Date: Wed, 21 Jan 2026 21:32:42 -0500 Subject: [PATCH] appease cppcheck --- src/activities/bluetooth/BluetoothActivity.cpp | 13 +++++++------ src/activities/bluetooth/BluetoothActivity.h | 9 +++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/activities/bluetooth/BluetoothActivity.cpp b/src/activities/bluetooth/BluetoothActivity.cpp index 83df6462..2e8a088d 100644 --- a/src/activities/bluetooth/BluetoothActivity.cpp +++ b/src/activities/bluetooth/BluetoothActivity.cpp @@ -54,10 +54,10 @@ void BluetoothActivity::onEnter() { Activity::onEnter(); NimBLEDevice::init(DEVICE_NAME); - pServer = NimBLEDevice::createServer(); + NimBLEServer *pServer = NimBLEDevice::createServer(); pServer->setCallbacks(&serverCallbacks, false); - pService = pServer->createService(SERVICE_UUID); - pRequestChar = pService->createCharacteristic( + NimBLEService *pService = pServer->createService(SERVICE_UUID); + NimBLECharacteristic *pRequestChar = pService->createCharacteristic( REQUEST_CHARACTERISTIC_UUID, NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR ); @@ -116,7 +116,8 @@ void BluetoothActivity::intoState(State newState) { { // caller sets errorMessage file.close(); - if (pServer->getConnectedCount() > 0) { + NimBLEServer* pServer = NimBLEDevice::getServer(); + if (pServer != nullptr && pServer->getConnectedCount() > 0) { // TODO: send back a response over BLE? pServer->disconnect(pServer->getPeerInfo(0)); } @@ -299,7 +300,7 @@ void BluetoothActivity::onRequest(lfbt_message* msg, size_t msg_len) { filepath = OUTPUT_DIRECTORY "/" + filename; } - PROTOCOL_ASSERT(SdMan.openFileForWrite("BT", filepath, file), "Couldn't open file %s for writing", filepath); + PROTOCOL_ASSERT(SdMan.openFileForWrite("BT", filepath, file), "Couldn't open file %s for writing", filepath.c_str()); // TODO: would be neat to check if we have enough space, but SDCardManager doesn't seem to expose that info currently txnId = msg->txnId; @@ -326,7 +327,7 @@ void BluetoothActivity::onRequest(lfbt_message* msg, size_t msg_len) { msg_len - 8 - sizeof(lfbt_msg_client_chunk) ); PROTOCOL_ASSERT(state == STATE_OFFERED || state == STATE_RECEIVING, "Invalid state for client_chunk: %d", state); - PROTOCOL_ASSERT(msg->body.clientChunk.offset == receivedBytes, "Expected chunk %d, got %d", receivedBytes, msg->body.clientChunk.offset); + PROTOCOL_ASSERT(msg->body.clientChunk.offset == receivedBytes, "Expected chunk %zu, got %u", receivedBytes, msg->body.clientChunk.offset); size_t written = file.write((uint8_t*)msg->body.clientChunk.body, msg_len - 8 - sizeof(lfbt_msg_client_chunk)); PROTOCOL_ASSERT(written > 0, "Couldn't write to file"); diff --git a/src/activities/bluetooth/BluetoothActivity.h b/src/activities/bluetooth/BluetoothActivity.h index c30c3eaf..4f91f5b3 100644 --- a/src/activities/bluetooth/BluetoothActivity.h +++ b/src/activities/bluetooth/BluetoothActivity.h @@ -89,10 +89,7 @@ class BluetoothActivity final : public Activity { RequestCallbacks requestCallbacks; - NimBLEServer *pServer; - NimBLEService *pService; - NimBLECharacteristic *pRequestChar, *pResponseChar; - NimBLEAdvertising *pAdvertising; + NimBLECharacteristic *pResponseChar = nullptr; void startAdvertising(); void stopAdvertising(); @@ -111,8 +108,8 @@ class BluetoothActivity final : public Activity { FsFile file; size_t receivedBytes = 0; size_t totalBytes = 0; - char errorMessage[256]; - uint32_t txnId; + char errorMessage[256] = {}; + uint32_t txnId = 0; void intoState(State newState);