Skip to content

Commit 2129042

Browse files
committed
more security
1 parent bb9c74c commit 2129042

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

include/geode/basic/mapping.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,16 @@ namespace geode
198198

199199
void unmap( const T1& in, const T2& out )
200200
{
201+
if( !this->has_mapping_input( in ) )
202+
{
203+
return;
204+
}
201205
auto& in_map = this->in2out_mapping().at( in );
202206
const auto itr = absl::c_find( in_map, out );
207+
if( itr == in_map.end() )
208+
{
209+
return;
210+
}
203211
in_map.erase( itr );
204212
if( this->in2out( in ).empty() )
205213
{

include/geode/mesh/helpers/detail/component_identifier.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace geode
5353

5454
index_t identify_vertices();
5555

56+
index_t identify_vertices( index_t nb_max_vertices );
57+
5658
[[nodiscard]] index_t vertex_identifier( index_t vertex_id ) const;
5759

5860
[[nodiscard]] absl::FixedArray< std::vector< index_t > >

src/geode/mesh/helpers/detail/component_identifier.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <geode/basic/attribute.hpp>
2929
#include <geode/basic/attribute_manager.hpp>
30+
#include <geode/basic/logger.hpp>
3031
#include <geode/basic/pimpl_impl.hpp>
3132

3233
#include <geode/mesh/core/edged_curve.hpp>
@@ -78,12 +79,17 @@ namespace geode
7879
}
7980

8081
index_t identify_elements()
82+
{
83+
return identify_elements( mesh_.nb_vertices() );
84+
}
85+
86+
index_t identify_elements( index_t nb_max_vertices )
8187
{
8288
for( const auto p : Indices{ identification_ } )
8389
{
8490
if( identifier( p ) == NO_ID )
8591
{
86-
propagate( p, nb_components_ );
92+
propagate( p, nb_components_, nb_max_vertices );
8793
nb_components_++;
8894
}
8995
}
@@ -114,11 +120,13 @@ namespace geode
114120
}
115121

116122
private:
117-
void propagate( index_t element_from, index_t tag_id )
123+
void propagate(
124+
index_t element_from, index_t tag_id, index_t nb_max_vertices )
118125
{
126+
index_t counter{ 0 };
119127
std::queue< index_t > queue;
120128
queue.emplace( element_from );
121-
while( !queue.empty() )
129+
while( !queue.empty() && counter < nb_max_vertices )
122130
{
123131
const auto cur_el = queue.front();
124132
queue.pop();
@@ -127,8 +135,10 @@ namespace geode
127135
continue;
128136
}
129137
identification_[cur_el] = tag_id;
138+
counter++;
130139
add_adjacents( cur_el, queue );
131140
}
141+
DEBUG( counter );
132142
}
133143

134144
virtual void add_adjacents(
@@ -176,6 +186,11 @@ namespace geode
176186
return impl_->identify_elements();
177187
}
178188

189+
index_t GraphIdentifier::identify_vertices( index_t nb_max_vertices )
190+
{
191+
return impl_->identify_elements( nb_max_vertices );
192+
}
193+
179194
index_t GraphIdentifier::vertex_identifier( index_t vertex_id ) const
180195
{
181196
return impl_->identifier( vertex_id );

0 commit comments

Comments
 (0)