Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
9 changes: 9 additions & 0 deletions src/cubeb_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ class auto_array
*/
void push(const T * elements, size_t length)
{
if (!length) {
return;
}
if (length_ + length > capacity_) {
reserve(length_ + length);
}
Expand All @@ -205,6 +208,9 @@ class auto_array
*/
void push_silence(size_t length)
{
if (!length) {
return;
}
if (length_ + length > capacity_) {
reserve(length + length_);
}
Expand All @@ -218,6 +224,9 @@ class auto_array
*/
void push_front_silence(size_t length)
{
if (!length) {
return;
}
if (length_ + length > capacity_) {
reserve(length + length_);
}
Expand Down
18 changes: 18 additions & 0 deletions test/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,21 @@ TEST(cubeb, auto_array)
ASSERT_EQ(array.capacity(), 20u);
}

// On debug build this was crashing in PodMove/Zero/Copy() methods
// used by auto_array
TEST(cubeb, auto_array_zero_length_crash)
{
auto_array<float> array;

ASSERT_EQ(array.length(), 0u);
ASSERT_EQ(array.capacity(), 0u);

float data[3] = {};
array.push(data, 0);
array.push_silence(0);
array.push_front_silence(0);

ASSERT_EQ(array.length(), 0u);
ASSERT_EQ(array.capacity(), 0u);
}