tint: Fix utils::Vector<T, 0>::Push segfaulting
Grow multiplies capacity by 2, but for a 0-sized Vector (i.e. no small array), capacity is 0, so Grow wouldn't grow. Bug: tint:1613 Change-Id: I6f2954cbfdb0c638e02b2f441e17a016c0198ad7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98540 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
953d610aa2
commit
1884c964d7
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -461,7 +462,7 @@ class Vector {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Expands the capacity of the vector
|
/// Expands the capacity of the vector
|
||||||
void Grow() { Reserve(impl_.slice.cap * 2); }
|
void Grow() { Reserve(std::max(impl_.slice.cap, static_cast<size_t>(1)) * 2); }
|
||||||
|
|
||||||
/// Moves 'other' to this vector, if possible, otherwise performs a copy.
|
/// Moves 'other' to this vector, if possible, otherwise performs a copy.
|
||||||
void MoveOrCopy(VectorRef<T>&& other) {
|
void MoveOrCopy(VectorRef<T>&& other) {
|
||||||
|
|
|
@ -151,6 +151,17 @@ TEST(TintVectorTest, InitializerList_NoSmallArray) {
|
||||||
EXPECT_TRUE(AllExternallyHeld(vec));
|
EXPECT_TRUE(AllExternallyHeld(vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(TintVectorTest, Push_NoSmallArray) {
|
||||||
|
Vector<std::string, 0> vec;
|
||||||
|
vec.Push("one");
|
||||||
|
vec.Push("two");
|
||||||
|
EXPECT_EQ(vec.Length(), 2u);
|
||||||
|
EXPECT_EQ(vec.Capacity(), 2u);
|
||||||
|
EXPECT_EQ(vec[0], "one");
|
||||||
|
EXPECT_EQ(vec[1], "two");
|
||||||
|
EXPECT_TRUE(AllExternallyHeld(vec));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(TintVectorTest, InferTN_1CString) {
|
TEST(TintVectorTest, InferTN_1CString) {
|
||||||
auto vec = Vector{"one"};
|
auto vec = Vector{"one"};
|
||||||
static_assert(std::is_same_v<decltype(vec)::value_type, const char*>);
|
static_assert(std::is_same_v<decltype(vec)::value_type, const char*>);
|
||||||
|
|
Loading…
Reference in New Issue