InlinedVector: Correct the computation of max_size()

Corrects the computation of max_size(), so that it accounts for the
size of the objects.

PiperOrigin-RevId: 471343778
Change-Id: I68e222cefaa0295b8d8c38d00308a29df4165e81
pull/1267/head
Derek Mauro 3 years ago committed by Copybara-Service
parent 6a262fdadd
commit 43d3c7a4e2
  1. 5
      absl/container/inlined_vector.h
  2. 1
      absl/container/inlined_vector_test.cc

@ -275,8 +275,9 @@ class InlinedVector {
size_type max_size() const noexcept {
// One bit of the size storage is used to indicate whether the inlined
// vector contains allocated memory. As a result, the maximum size that the
// inlined vector can express is half of the max for `size_type`.
return (std::numeric_limits<size_type>::max)() / 2;
// inlined vector can express is half of the max for
// AllocatorTraits<A>::max_size();
return AllocatorTraits<A>::max_size(storage_.GetAllocator()) / 2;
}
// `InlinedVector::capacity()`

@ -255,6 +255,7 @@ TEST(IntVec, Hardened) {
#if !defined(NDEBUG) || ABSL_OPTION_HARDENED
EXPECT_DEATH_IF_SUPPORTED(v[10], "");
EXPECT_DEATH_IF_SUPPORTED(v[-1], "");
EXPECT_DEATH_IF_SUPPORTED(v.resize(v.max_size() + 1), "");
#endif
}

Loading…
Cancel
Save