mirror of
https://github.com/facebook/rocksdb.git
synced 2026-07-07 14:47:40 +08:00
Make autovector call default constructor explicitly before move/copy (#12499)
Summary: Make `autovector` constructs the stack based element in place before move or copy another `autovector`'s stack based elements. This is already done in the move/copy version of `autovector::push_back` when adding item to the stack based memory https://github.com/facebook/rocksdb/blob/8e6e8957fbb90992d1ac0c9996c70998751bd621/util/autovector.h#L269-L285 The ` values_ = reinterpret_cast<pointer>(buf_);` statement is not sufficient to ensure the class's member variables are properly constructed. I'm able to reproduce this consistently in a unit test in this change: https://github.com/facebook/rocksdb/compare/main...jowlyzhang:fix_sv_install with unit test: `./tiered_compaction_test --gtest_filter="\*FastTrack\*" With below stack trace P1203997597 showing the `std::string` copy destination is invalid, which indicates the object in the destination `autovector` is not constructed properly. Pull Request resolved: https://github.com/facebook/rocksdb/pull/12499 Test Plan: Existing unit tests. Reviewed By: anand1976 Differential Revision: D55662354 Pulled By: jowlyzhang fbshipit-source-id: 581ceb11155d3dd711998607ec6950c0e327556a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c4df598b8e
commit
2207a66fe5
@@ -371,6 +371,9 @@ autovector<T, kSize>& autovector<T, kSize>::assign(
|
||||
|
||||
// copy array
|
||||
num_stack_items_ = other.num_stack_items_;
|
||||
for (size_t i = 0; i < num_stack_items_; ++i) {
|
||||
new ((void*)(&values_[i])) value_type();
|
||||
}
|
||||
std::copy(other.values_, other.values_ + num_stack_items_, values_);
|
||||
|
||||
return *this;
|
||||
@@ -385,6 +388,7 @@ autovector<T, kSize>& autovector<T, kSize>::operator=(
|
||||
num_stack_items_ = n;
|
||||
other.num_stack_items_ = 0;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
new ((void*)(&values_[i])) value_type();
|
||||
values_[i] = std::move(other.values_[i]);
|
||||
}
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user