Skip to content
Browse files

core: Fix blob x shifting on invalid value

The code was sometimes using front() on an empty list. This is
undefined behavior.

 LocalWords:  unstage src config
  • Loading branch information...
1 parent 6b0a8e5 commit ac36bcd0038b0d2ffe216afeb0328315031531b7 Zack Moratto committed Mar 24, 2013
Showing with 16 additions and 3 deletions.
  1. +8 −2 src/asp/Core/BlobIndexThreaded.cc
  2. +8 −1 src/asp/Core/BlobIndexThreaded.h
View
10 src/asp/Core/BlobIndexThreaded.cc
@@ -303,8 +303,14 @@ void BlobCompressed::absorb( BlobCompressed const& victim ) {
temp_end.end() );
}
// Recalculate min.x()
- int32 lowest_value = 0;
- for ( uint32 i = 0; i < m_row_start.size(); i++ ) {
+ int32 valid_first = 0;
+ while ( valid_first < m_row_start.size() ) {
+ if ( m_row_start[valid_first].size() )
+ break;
+ valid_first++;
+ }
+ int32 lowest_value = m_row_start[valid_first].front();
+ for ( uint32 i = ++valid_first; i < m_row_start.size(); i++ ) {
if ( m_row_start[i].front() < lowest_value )
lowest_value = m_row_start[i].front();
}
View
9 src/asp/Core/BlobIndexThreaded.h
@@ -61,7 +61,14 @@ namespace blob {
BlobCompressed( vw::Vector2i const& top_left,
std::vector<std::list<vw::int32> > const& row_start,
std::vector<std::list<vw::int32> > const& row_end ) :
- m_min(top_left), m_row_start(row_start), m_row_end(row_end) {}
+ m_min(top_left), m_row_start(row_start), m_row_end(row_end) {
+ VW_DEBUG_ASSERT( row_start.size() == row_end.size(),
+ vw::InputErr() << "Input vectors do not have the same length." );
+ for ( size_t i = 0; i < row_start.size(); i++ ) {
+ VW_DEBUG_ASSERT( row_start[i].size() == row_end[i].size(),
+ vw::InputErr() << "List at row " << i << " doesn't have matched starts and ends." );
+ }
+ }
BlobCompressed() { m_min = vw::Vector2i(-1,-1); }
// Standard Access point

0 comments on commit ac36bcd

Please sign in to comment.
Something went wrong with that request. Please try again.