Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert regression of memory unsafe append_array (same vector into same vector). #101386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/templates/local_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class LocalVector {
return data;
}

// Must take a copy instead of a reference (see GH-31736).
_FORCE_INLINE_ void push_back(T p_elem) {
if (unlikely(count == capacity)) {
capacity = tight ? (capacity + 1) : MAX((U)1, capacity << 1);
Expand Down
7 changes: 5 additions & 2 deletions core/templates/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Vector {
CowData<T> _cowdata;

public:
// Must take a copy instead of a reference (see GH-31736).
bool push_back(T p_elem);
_FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias
void fill(T p_elem);
Expand Down Expand Up @@ -99,12 +100,14 @@ class Vector {
Error resize(Size p_size) { return _cowdata.resize(p_size); }
Error resize_zeroed(Size p_size) { return _cowdata.template resize<true>(p_size); }
_FORCE_INLINE_ const T &operator[](Size p_index) const { return _cowdata.get(p_index); }
// Must take a copy instead of a reference (see GH-31736).
Error insert(Size p_pos, T p_val) { return _cowdata.insert(p_pos, p_val); }
Size find(const T &p_val, Size p_from = 0) const { return _cowdata.find(p_val, p_from); }
Size rfind(const T &p_val, Size p_from = -1) const { return _cowdata.rfind(p_val, p_from); }
Size count(const T &p_val) const { return _cowdata.count(p_val); }

void append_array(const Vector<T> &p_other);
// Must take a copy instead of a reference (see GH-31736).
void append_array(Vector<T> p_other);

_FORCE_INLINE_ bool has(const T &p_val) const { return find(p_val) != -1; }

Expand Down Expand Up @@ -301,7 +304,7 @@ void Vector<T>::reverse() {
}

template <typename T>
void Vector<T>::append_array(const Vector<T> &p_other) {
void Vector<T>::append_array(Vector<T> p_other) {
const Size ds = p_other.size();
if (ds == 0) {
return;
Expand Down