From 123825d4831f39b9be05497f47864ece3f3285f7 Mon Sep 17 00:00:00 2001 From: h2zero Date: Wed, 13 Apr 2022 20:36:37 -0600 Subject: [PATCH] Fix health model fault reporting. --- src/NimBLEMeshModel.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/NimBLEMeshModel.cpp b/src/NimBLEMeshModel.cpp index e4f57c6..63f7644 100644 --- a/src/NimBLEMeshModel.cpp +++ b/src/NimBLEMeshModel.cpp @@ -617,13 +617,13 @@ int NimBLEHealthSrvCallbacks::faultGetCurrent(bt_mesh_model *model, uint8_t *tes uint16_t *company_id, uint8_t *faults, uint8_t *fault_count) { - NIMBLE_LOGD(LOG_TAG, "faultGetCurrent - default"); + NIMBLE_LOGD(LOG_TAG, "faultGetCurrent"); NimBLEHealthSrvModel* pModel = (NimBLEHealthSrvModel*)NimBLEDevice::getMeshNode()->getHealthModel(model); *test_id = pModel->m_testId; *company_id = CID_VENDOR; - faults = &pModel->m_faults[0]; - *fault_count = pModel->m_faults.size(); + *fault_count = std::min(*(size_t*)fault_count, pModel->m_faults.size()); + memcpy(faults, &pModel->m_faults[0], *fault_count); return 0; } @@ -631,7 +631,7 @@ int NimBLEHealthSrvCallbacks::faultGetRegistered(bt_mesh_model *model, uint16_t uint8_t *test_id, uint8_t *faults, uint8_t *fault_count) { - NIMBLE_LOGD(LOG_TAG, "faultGetRegistered - default"); + NIMBLE_LOGD(LOG_TAG, "faultGetRegistered"); if (company_id != CID_VENDOR) { return -BLE_HS_EINVAL; @@ -639,8 +639,8 @@ int NimBLEHealthSrvCallbacks::faultGetRegistered(bt_mesh_model *model, uint16_t NimBLEHealthSrvModel* pModel = (NimBLEHealthSrvModel*)NimBLEDevice::getMeshNode()->getHealthModel(model); *test_id = pModel->m_testId; - faults = &pModel->m_faults[0]; - *fault_count = pModel->m_faults.size(); + *fault_count = std::min(*(size_t*)fault_count, pModel->m_faults.size()); + memcpy(faults, &pModel->m_faults[0], *fault_count); return 0; }