Skip to content

Commit

Permalink
Validate allocated DataNode is not null
Browse files Browse the repository at this point in the history
  • Loading branch information
brawner committed Mar 29, 2024
1 parent f1133d5 commit 2173f60
Showing 1 changed file with 55 additions and 29 deletions.
84 changes: 55 additions & 29 deletions include/etl/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,9 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(map_full));

// Get next available free node
Data_Node& node = allocate_data_node_with_key(etl::move(key));
Data_Node* node = allocate_data_node_with_key(etl::move(key));

ETL_ASSERT(node != ETL_NULLPTR, ETL_ERROR(map_full));

// Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate)
inserted_node = insert_node(root_node, node);
Expand Down Expand Up @@ -965,10 +967,12 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(map_full));

// Get next available free node
Data_Node& node = allocate_data_node_with_key(key);
Data_Node* node = allocate_data_node_with_key(key);

ETL_ASSERT(node != ETL_NULLPTR, ETL_ERROR(map_full));

// Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate)
inserted_node = insert_node(root_node, node);
inserted_node = insert_node(root_node, *node);

// Insert node into tree and return iterator to new node location in tree
i_element = iterator(*this, inserted_node);
Expand Down Expand Up @@ -1213,10 +1217,12 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(map_full));

// Get next available free node
Data_Node& node = allocate_data_node(value);
Data_Node* node = allocate_data_node(value);

ETL_ASSERT(node != ETL_NULLPTR, ETL_ERROR(map_full));

// Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate)
inserted_node = insert_node(root_node, node);
inserted_node = insert_node(root_node, *node);
inserted = inserted_node == &node;

// Insert node into tree and return iterator to new node location in tree
Expand All @@ -1238,10 +1244,12 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(map_full));

// Get next available free node
Data_Node& node = allocate_data_node(etl::move(value));
Data_Node* node = allocate_data_node(etl::move(value));

ETL_ASSERT(node != ETL_NULLPTR, ETL_ERROR(map_full));

// Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate)
inserted_node = insert_node(root_node, node);
inserted_node = insert_node(root_node, *node);
inserted = inserted_node == &node;

// Insert node into tree and return iterator to new node location in tree
Expand All @@ -1263,10 +1271,12 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(map_full));

// Get next available free node
Data_Node& node = allocate_data_node(value);
Data_Node* node = allocate_data_node(value);

ETL_ASSERT(node != ETL_NULLPTR, ETL_ERROR(map_full));

// Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate)
inserted_node = insert_node(root_node, node);
inserted_node = insert_node(root_node, *node);

// Insert node into tree and return iterator to new node location in tree
return iterator(*this, inserted_node);
Expand All @@ -1287,10 +1297,12 @@ namespace etl
ETL_ASSERT(!full(), ETL_ERROR(map_full));

// Get next available free node
Data_Node& node = allocate_data_node(etl::move(value));
Data_Node* node = allocate_data_node(etl::move(value));

ETL_ASSERT(node != ETL_NULLPTR, ETL_ERROR(map_full));

// Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate)
inserted_node = insert_node(root_node, node);
inserted_node = insert_node(root_node, *node);

// Insert node into tree and return iterator to new node location in tree
return iterator(*this, inserted_node);
Expand Down Expand Up @@ -1494,23 +1506,30 @@ namespace etl
//*************************************************************************
/// Allocate a Data_Node.
//*************************************************************************
Data_Node& allocate_data_node(const_reference value)
Data_Node* allocate_data_node(const_reference value)
{
Data_Node& node = allocate_data_node();
::new (&node.value) value_type(value);
Data_Node* node = allocate_data_node();
if (node == ETL_NULLPTR)
{
return ETL_NULLPTR;
}
::new (&node->value) value_type(value);
ETL_INCREMENT_DEBUG_COUNT;
return node;
}

//*************************************************************************
/// Allocate a Data_Node with the supplied key.
//*************************************************************************
Data_Node& allocate_data_node_with_key(const_key_reference key)
Data_Node* allocate_data_node_with_key(const_key_reference key)
{
Data_Node& node = allocate_data_node();

::new ((void*)etl::addressof(node.value.first)) key_type(key);
::new ((void*)etl::addressof(node.value.second)) mapped_type();
Data_Node* node = allocate_data_node();
if (node == ETL_NULLPTR)
{
return ETL_NULLPTR;
}
::new ((void*)etl::addressof(node->value.first)) key_type(key);
::new ((void*)etl::addressof(node->value.second)) mapped_type();
ETL_INCREMENT_DEBUG_COUNT;
return node;
}
Expand All @@ -1519,23 +1538,30 @@ namespace etl
//*************************************************************************
/// Allocate a Data_Node.
//*************************************************************************
Data_Node& allocate_data_node(rvalue_reference value)
Data_Node* allocate_data_node(rvalue_reference value)
{
Data_Node& node = allocate_data_node();
::new (&node.value) value_type(etl::move(value));
Data_Node* node = allocate_data_node();
if (node == ETL_NULLPTR)
{
return ETL_NULLPTR;
}
::new (&node->value) value_type(etl::move(value));
ETL_INCREMENT_DEBUG_COUNT;
return node;
}

//*************************************************************************
/// Allocate a Data_Node with the supplied key.
//*************************************************************************
Data_Node& allocate_data_node_with_key(rvalue_key_reference key)
Data_Node* allocate_data_node_with_key(rvalue_key_reference key)
{
Data_Node& node = allocate_data_node();

::new ((void*)etl::addressof(node.value.first)) key_type(etl::move(key));
::new ((void*)etl::addressof(node.value.second)) mapped_type();
Data_Node* node = allocate_data_node();
if (node == ETL_NULLPTR)
{
return ETL_NULLPTR;
}
::new ((void*)etl::addressof(node->value.first)) key_type(etl::move(key));
::new ((void*)etl::addressof(node->value.second)) mapped_type();
ETL_INCREMENT_DEBUG_COUNT;
return node;
}
Expand All @@ -1545,10 +1571,10 @@ namespace etl
//*************************************************************************
/// Create a Data_Node.
//*************************************************************************
Data_Node& allocate_data_node()
Data_Node* allocate_data_node()
{
Data_Node* (etl::ipool::*func)() = &etl::ipool::allocate<Data_Node>;
return *(p_node_pool->*func)();
return (p_node_pool->*func)();
}

//*************************************************************************
Expand Down

0 comments on commit 2173f60

Please sign in to comment.