diff --git a/src/hotspot/share/utilities/growableArray.cpp b/src/hotspot/share/utilities/growableArray.cpp index 2a550a3f8a0..6a1cb0b0414 100644 --- a/src/hotspot/share/utilities/growableArray.cpp +++ b/src/hotspot/share/utilities/growableArray.cpp @@ -43,6 +43,11 @@ void* GrowableArrayArenaAllocator::allocate(int max, int element_size, Arena* ar void* GrowableArrayCHeapAllocator::allocate(int max, int element_size, MemTag mem_tag) { assert(max >= 0, "integer overflow"); + + if (max == 0) { + return nullptr; + } + size_t byte_size = element_size * (size_t) max; // memory tag has to be specified for C heap allocation diff --git a/src/hotspot/share/utilities/growableArray.hpp b/src/hotspot/share/utilities/growableArray.hpp index 5dec089a4fb..31e797fc192 100644 --- a/src/hotspot/share/utilities/growableArray.hpp +++ b/src/hotspot/share/utilities/growableArray.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -811,10 +811,6 @@ class GrowableArrayCHeap : public GrowableArrayWithAllocator