Skip to content

Commit 5d42fce

Browse files
committed
Improve bounds checking in reallocation_size
1 parent b0fdeb0 commit 5d42fce

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

source/containers/reallocation_size.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
export module containers.reallocation_size;
77

88
import bounded;
9+
import numeric_traits;
910

1011
using namespace bounded::literal;
1112

@@ -15,7 +16,10 @@ export template<typename Capacity>
1516
constexpr auto reallocation_size(Capacity const current_capacity, auto const current_size, auto const extra_elements) {
1617
return ::bounded::assume_in_range<Capacity>(bounded::max(
1718
bounded::integer(current_size) + bounded::integer(extra_elements),
18-
bounded::integer(current_capacity) * 2_bi
19+
bounded::min(
20+
bounded::integer(current_capacity) * 2_bi,
21+
numeric_traits::max_value<Capacity>
22+
)
1923
));
2024
}
2125

0 commit comments

Comments
 (0)