fix nodeDB erase loop when free mem returns invalid value (0, -1). (#5519)

Co-authored-by: mverch67 <manuel.verch@gmx.de>
This commit is contained in:
Tom Fifield 2024-12-07 11:39:30 +11:00 committed by GitHub
parent de774188c9
commit bac9fec17f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1372,11 +1372,14 @@ meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n)
if (oldestBoringIndex != -1) {
oldestIndex = oldestBoringIndex;
}
// Shove the remaining nodes down the chain
for (int i = oldestIndex; i < numMeshNodes - 1; i++) {
meshNodes->at(i) = meshNodes->at(i + 1);
if (oldestIndex != -1) {
// Shove the remaining nodes down the chain
for (int i = oldestIndex; i < numMeshNodes - 1; i++) {
meshNodes->at(i) = meshNodes->at(i + 1);
}
(numMeshNodes)--;
}
(numMeshNodes)--;
}
// add the node at the end
lite = &meshNodes->at((numMeshNodes)++);