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

This commit is contained in:
mverch67 2024-11-08 23:06:46 +01:00
parent 44ebb6ddff
commit 5b135ec3dc

View File

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