fix(peer): GetNumberOfAddresses() always returned MAXIMUM_NUMBER_OF_INTERNAL_IDS - #43
Conversation
…NTERNAL_IDS The loop's unassigned-entry check was dead code: the loop condition already excluded unassigned entries, so reaching the end of the real address list exited the loop and fell through to returning MAXIMUM_NUMBER_OF_INTERNAL_IDS (10) regardless of how many local addresses exist. Callers iterating GetLocalIP(0..count-1) then printed UNASSIGNED_SYSTEM_ADDRESS garbage entries. Inherited from SLikeNet (SLikeSoft#55).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. Walkthrough
ChangesLocal address count
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The PR makes GetNumberOfAddresses() return the actual number of assigned local addresses, preventing callers from iterating into unassigned entries; the reported test suites pass, and no actionable merge-blocking risk remains. Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
RakPeer::GetNumberOfAddresses()always returnedMAXIMUM_NUMBER_OF_INTERNAL_IDS(10) instead of the actual number of local addresses. The loop's unassigned-entry check was dead code — the loop condition already excluded unassigned entries, so hitting the end of the real address list exited the loop and fell through to the max-value return. Callers iteratingGetLocalIP(0..count-1)then printedUNASSIGNED_SYSTEM_ADDRESSgarbage entries, andIsLocalIP()compared against those garbage slots too.Inherited from SLikeNet, where it was introduced when the original RakNet counting loop was rewritten: SLikeSoft#55.
Fix
Count leading assigned entries and return that count (
Source/src/RakPeer.cpp).Tests
New hermetic unit tests in
Tests/Unit/LocalAddressTests.cppassert that every index below the returned count is a real address and that the entry at the count boundary is unassigned, both beforeStartup()and on a started-but-unconnected peer.--gtest_repeatruns.Summary by CodeRabbit
Bug Fixes
Tests