RFR: JDK-8284178: os::commit_memory() should assert the given range [v2]

Aleksey Shipilev shade at openjdk.java.net
Thu Apr 7 09:30:45 UTC 2022


On Thu, 7 Apr 2022 04:46:18 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> Trivial fix to assert that ranges given to os::commit/uncommit/release_memory are not empty.
>> 
>> I recently hunted an error where the memory reservation failed, was not handled, and the null pointer was accidentally passed to os::commit_memory(). The resulting `mmap()` failed and this looked like a commit error, when it really was a reservation error. An assert would have saved me time.
>
> Thomas Stuefe has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Alexey-feedback

src/hotspot/share/runtime/os.cpp line 1680:

> 1678: static void assert_nonempty_range(const char* addr, size_t bytes) {
> 1679:   assert(addr != nullptr && bytes > 0, "invalid range [" PTR_FORMAT ", " PTR_FORMAT ")",
> 1680:          p2i(addr), p2i(addr + bytes));

I think `p2i(addr + bytes)` is UB when `addr` is `nullptr`? `p2i(addr) + bytes` is safer?

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

PR: https://git.openjdk.java.net/jdk/pull/8075


More information about the hotspot-runtime-dev mailing list