[Bugfix] Delete all bonds does not allow re-pairing.#404
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughArr, matey! This change be replacin' the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/NimBLEDevice.cpp (1)
632-638: Ahoy, sailor! Consider cachin' the address before ye walk the plank, arr!The
getBondedAddress(i)be called twice when a deletion fails - once fer thedeleteBond()call on line 634, and again fer the error log on line 635. While this be only happenin' in the error path (a rare voyage indeed), ye could stash the address in a local variable fer cleaner seas:🏴☠️ Proposed treasure map to cleaner code
bool NimBLEDevice::deleteAllBonds() { int numBonds = NimBLEDevice::getNumBonds(); for (int i = numBonds - 1; i >= 0; i--) { - if (!NimBLEDevice::deleteBond(NimBLEDevice::getBondedAddress(i))) { - NIMBLE_LOGE(LOG_TAG, "Failed to delete bond for address: %s", NimBLEDevice::getBondedAddress(i).toString().c_str()); + NimBLEAddress addr = NimBLEDevice::getBondedAddress(i); + if (!NimBLEDevice::deleteBond(addr)) { + NIMBLE_LOGE(LOG_TAG, "Failed to delete bond for address: %s", addr.toString().c_str()); return false; } } return true; }The backwards iteration be a fine choice, matey! It keeps the indices shipshape as bonds be removed from the list. Yarrr! 🦜
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/NimBLEDevice.cpp` around lines 632 - 638, Cache the bonded address into a local variable before calling NimBLEDevice::deleteBond so you don't call NimBLEDevice::getBondedAddress(i) twice on the error path; specifically, inside the loop that uses NimBLEDevice::getNumBonds() and iterates i from numBonds-1 down to 0, assign auto addr = NimBLEDevice::getBondedAddress(i) then call NimBLEDevice::deleteBond(addr) and, if it fails, log addr.toString().c_str() in the NIMBLE_LOGE call and return false as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/NimBLEDevice.cpp`:
- Around line 632-638: Cache the bonded address into a local variable before
calling NimBLEDevice::deleteBond so you don't call
NimBLEDevice::getBondedAddress(i) twice on the error path; specifically, inside
the loop that uses NimBLEDevice::getNumBonds() and iterates i from numBonds-1
down to 0, assign auto addr = NimBLEDevice::getBondedAddress(i) then call
NimBLEDevice::deleteBond(addr) and, if it fails, log addr.toString().c_str() in
the NIMBLE_LOGE call and return false as before.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3581199e-63ae-4393-94b4-1f00191b2f07
📒 Files selected for processing (1)
src/NimBLEDevice.cpp
This change iterates through each bond and unpairs it rather than just deleting the bond data in nvs, allowing a connected peer to rebond.
b0a3d05 to
7c4fe48
Compare
This change iterates through each bond and unpairs it rather than just deleting the bond data in nvs, allowing a connected peer to rebond.
Summary by CodeRabbit