Skip to content

Commit 9477550

Browse files
committed
fix: use m_whiteList.data() - operator[] on an empty vector is UB
After erasing the last whitelist entry, &m_whiteList[0] indexes an empty vector before ble_gap_wl_set(..., 0). data() is well-defined for empty vectors; same change applied to the whiteListAdd call site for consistency.
1 parent 2534e1d commit 9477550

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/NimBLEDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ bool NimBLEDevice::onWhiteList(const NimBLEAddress& address) {
728728
bool NimBLEDevice::whiteListAdd(const NimBLEAddress& address) {
729729
if (!NimBLEDevice::onWhiteList(address)) {
730730
m_whiteList.push_back(address);
731-
int rc = ble_gap_wl_set(reinterpret_cast<ble_addr_t*>(&m_whiteList[0]), m_whiteList.size());
731+
int rc = ble_gap_wl_set(reinterpret_cast<ble_addr_t*>(m_whiteList.data()), m_whiteList.size());
732732
if (rc != 0) {
733733
NIMBLE_LOGE(LOG_TAG, "Failed adding to whitelist rc=%d", rc);
734734
m_whiteList.pop_back();
@@ -748,7 +748,7 @@ bool NimBLEDevice::whiteListRemove(const NimBLEAddress& address) {
748748
for (auto it = m_whiteList.begin(); it < m_whiteList.end(); ++it) {
749749
if (*it == address) {
750750
m_whiteList.erase(it);
751-
int rc = ble_gap_wl_set(reinterpret_cast<ble_addr_t*>(&m_whiteList[0]), m_whiteList.size());
751+
int rc = ble_gap_wl_set(reinterpret_cast<ble_addr_t*>(m_whiteList.data()), m_whiteList.size());
752752
if (rc != 0) {
753753
m_whiteList.push_back(address);
754754
NIMBLE_LOGE(LOG_TAG, "Failed removing from whitelist rc=%d", rc);

0 commit comments

Comments
 (0)