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

auto_array: protect from various calls when length_ is 0 #770

Merged
merged 1 commit into from
Dec 12, 2023
Merged
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
21 changes: 15 additions & 6 deletions src/cubeb_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ template <typename T> class auto_array {
if (length_ + length > capacity_) {
reserve(length_ + length);
}
PodCopy(data_ + length_, elements, length);
if (data_) {
PodCopy(data_ + length_, elements, length);
}
length_ += length;
}

Expand All @@ -195,21 +197,25 @@ template <typename T> class auto_array {
if (length_ + length > capacity_) {
reserve(length + length_);
}
PodZero(data_ + length_, length);
if (data_) {
PodZero(data_ + length_, length);
}
length_ += length;
}

/** Prepend `length` zero-ed elements to the end of the array, resizing the
* array if needed.
/** Prepend `length` zero-ed elements to the front of the array, resizing and
* shifting the array if needed.
* @parameter length the number of elements to prepend to the array.
*/
void push_front_silence(size_t length)
{
if (length_ + length > capacity_) {
reserve(length + length_);
}
PodMove(data_ + length, data_, length_);
PodZero(data_, length);
if (data_) {
PodMove(data_ + length, data_, length_);
PodZero(data_, length);
}
length_ += length;
}

Expand All @@ -227,6 +233,9 @@ template <typename T> class auto_array {
if (length > length_) {
return false;
}
if (!data_) {
return true;
}
if (elements) {
PodCopy(elements, data_, length);
}
Expand Down