Fix: Crash when reininitializing empty generic array
Noticed this while developing new code that used GArray.
This commit is contained in:
parent
b804f925c7
commit
fbbd7f0d5c
|
@ -231,7 +231,9 @@ class GArray {
|
|||
this->deallocate(new_data);
|
||||
throw;
|
||||
}
|
||||
this->deallocate(data_);
|
||||
if (this->data_) {
|
||||
this->deallocate(data_);
|
||||
}
|
||||
data_ = new_data;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,4 +114,13 @@ TEST(generic_array, InContainer)
|
|||
}
|
||||
}
|
||||
|
||||
TEST(generic_array, ReinitEmpty)
|
||||
{
|
||||
GArray<> array(CPPType::get<int>());
|
||||
array.reinitialize(10);
|
||||
array.as_mutable_span().typed<int>()[9] = 7;
|
||||
EXPECT_EQ(array.size(), 10);
|
||||
EXPECT_EQ(array.as_span().typed<int>()[9], 7);
|
||||
}
|
||||
|
||||
} // namespace blender::tests
|
||||
|
|
Loading…
Reference in New Issue