RFR: JDK-8312453: GrowableArray should assert for length overflow on append

Kim Barrett kbarrett at openjdk.org
Thu Jul 20 15:44:41 UTC 2023


On Thu, 20 Jul 2023 10:20:36 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> Trivial change to assert that we don't overflow on append.

I think these changes are not needed and should not be made.

src/hotspot/share/utilities/growableArray.hpp line 390:

> 388: public:
> 389:   int append(const E& elem) {
> 390:     assert(this->_len != INT_MAX, "Overflow");

This isn't needed.  `grow` (via `next_power_of_2`) already does the appropriate overflow checking.

src/hotspot/share/utilities/growableArray.hpp line 519:

> 517: void GrowableArrayWithAllocator<E, Derived>::grow(int j) {
> 518:   const size_t next_p2 = next_power_of_2((size_t)j);
> 519:   assert(next_p2 < INT_MAX, "GrowableArray overflow (current capacity: %d)", this->_capacity);

This isn't needed.  `next_power_of_2` has all the appropriate overflow checking assertions.
Just let it do it's thing with the original `int` argument.

-------------

Changes requested by kbarrett (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/14951#pullrequestreview-1539577342
PR Review Comment: https://git.openjdk.org/jdk/pull/14951#discussion_r1269652718
PR Review Comment: https://git.openjdk.org/jdk/pull/14951#discussion_r1269651817


More information about the hotspot-dev mailing list