mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Fix checking for special tree identifier value
Unsigned types are never negative, so the existant check does not make sense. Check correctly using the newly introduced TreeNode::IsValidIdentifier method.
This commit is contained in:
@@ -128,7 +128,7 @@ protected:
|
||||
void setIdentifierAndRetain(uint16_t newId);
|
||||
void setTo(const TreeHandle & tr);
|
||||
|
||||
static bool hasNode(uint16_t identifier) { return identifier < TreeNode::NoNodeIdentifier; }
|
||||
static bool hasNode(uint16_t identifier) { return TreeNode::IsValidIdentifier(identifier); }
|
||||
|
||||
/* Hierarchy operations */
|
||||
// Add
|
||||
|
||||
@@ -172,6 +172,8 @@ public:
|
||||
void log(std::ostream & stream, bool recursive = true);
|
||||
#endif
|
||||
|
||||
static bool IsValidIdentifier(uint16_t id) { return id < NoNodeIdentifier; }
|
||||
|
||||
protected:
|
||||
TreeNode() :
|
||||
m_identifier(NoNodeIdentifier),
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
// Node
|
||||
TreeNode * node(uint16_t identifier) const {
|
||||
assert(identifier >= 0 && identifier < MaxNumberOfNodes);
|
||||
assert(TreeNode::IsValidIdentifier(identifier) && identifier < MaxNumberOfNodes);
|
||||
if (m_nodeForIdentifierOffset[identifier] != UINT16_MAX) {
|
||||
return const_cast<TreeNode *>(reinterpret_cast<const TreeNode *>(m_alignedBuffer + m_nodeForIdentifierOffset[identifier]));
|
||||
}
|
||||
@@ -125,7 +125,7 @@ private:
|
||||
}
|
||||
}
|
||||
void push(uint16_t i) {
|
||||
assert(m_currentIndex >= 0 && m_currentIndex < MaxNumberOfNodes);
|
||||
assert(TreeNode::IsValidIdentifier(m_currentIndex) && m_currentIndex < MaxNumberOfNodes);
|
||||
m_availableIdentifiers[m_currentIndex++] = i;
|
||||
}
|
||||
uint16_t pop() {
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Poincare {
|
||||
TreePool * TreePool::SharedStaticPool = nullptr;
|
||||
|
||||
void TreePool::freeIdentifier(uint16_t identifier) {
|
||||
if (identifier >= 0 && identifier < MaxNumberOfNodes) {
|
||||
if (TreeNode::IsValidIdentifier(identifier) && identifier < MaxNumberOfNodes) {
|
||||
m_nodeForIdentifierOffset[identifier] = UINT16_MAX;
|
||||
m_identifiers.push(identifier);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user