From e3df4fe4b46baa88283416c92f8b85c59bb9518f Mon Sep 17 00:00:00 2001 From: Clemens H / OE1RFC / datacop Date: Thu, 10 Feb 2022 18:44:58 +0100 Subject: [PATCH] fix: log error if node_db is full instead of firmware crash (#1191) --- src/mesh/NodeDB.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 9647c7091..5eb8320ac 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -474,6 +474,9 @@ size_t NodeDB::getNumOnlineNodes() void NodeDB::updatePosition(uint32_t nodeId, const Position &p, RxSource src) { NodeInfo *info = getOrCreateNode(nodeId); + if (!info) { + return; + } if (src == RX_SRC_LOCAL) { // Local packet, fully authoritative @@ -517,6 +520,9 @@ void NodeDB::updatePosition(uint32_t nodeId, const Position &p, RxSource src) void NodeDB::updateUser(uint32_t nodeId, const User &p) { NodeInfo *info = getOrCreateNode(nodeId); + if (!info) { + return; + } DEBUG_MSG("old user %s/%s/%s\n", info->user.id, info->user.long_name, info->user.short_name); @@ -546,6 +552,9 @@ void NodeDB::updateFrom(const MeshPacket &mp) DEBUG_MSG("Update DB node 0x%x, rx_time=%u\n", mp.from, mp.rx_time); NodeInfo *info = getOrCreateNode(getFrom(&mp)); + if (!info) { + return; + } if (mp.rx_time) // if the packet has a valid timestamp use it to update our last_heard info->last_heard = mp.rx_time; @@ -572,8 +581,12 @@ NodeInfo *NodeDB::getOrCreateNode(NodeNum n) NodeInfo *info = getNode(n); if (!info) { + if (*numNodes >= MAX_NUM_NODES) { + screen->print("error: node_db full!\n"); + DEBUG_MSG("ERROR! could not create new node, node_db is full! (%d nodes)", *numNodes); + return NULL; + } // add the node - assert(*numNodes < MAX_NUM_NODES); info = &nodes[(*numNodes)++]; // everything is missing except the nodenum