Fix an assertion failure in IndexSet::do_add() following a table clear

We don't track insertions and deletions for tables that are merely linked to by
tables actually being observed (for performance reasons, since we don't need
that information), but the check for that was missing in one place. This would
be merely a slowdown rather than a crash, but deletions.add_shifted() can
overflow size_t if the passed-in index represents a newly inserted row and the
check for that didn't work due to not tracking insertions for the table.

The only remotely realistic way to actually have size_t overflow is to have
previously cleared the table (the table clear instruction does not include the
old size of the table, so it just marks {0, SIZE_T_MAX} as deleted).

Fixes #3537.
This commit is contained in:
Thomas Goyne 2016-05-10 13:44:51 -07:00
parent 2bcf42904a
commit e6d09b513e
1 changed files with 6 additions and 4 deletions

View File

@ -251,11 +251,13 @@ void CollectionChangeBuilder::move_over(size_t row_ndx, size_t last_row, bool tr
REALM_ASSERT(modifications.empty() || prev(modifications.end())->second - 1 <= last_row);
if (row_ndx == last_row) {
if (track_moves) {
auto shifted_from = insertions.erase_or_unshift(row_ndx);
if (shifted_from != IndexSet::npos)
deletions.add_shifted(shifted_from);
modifications.remove(row_ndx);
m_move_mapping.erase(row_ndx);
}
modifications.remove(row_ndx);
return;
}