RFR: 8346157: [Ubsan]: runtime error: pointer index expression with base 0x000000001000 overflowed to 0xfffffffffffffff0

Gerard Ziemski gziemski at openjdk.org
Thu Jan 2 16:35:35 UTC 2025


On Thu, 26 Dec 2024 09:11:15 GMT, Amit Kumar <amitkumar at openjdk.org> wrote:

> Fixes ubsan warning in mallocTracker.cpp

Changes requested by gziemski (Reviewer).

src/hotspot/share/nmt/mallocTracker.cpp line 243:

> 241:     const size_t smallest_possible_alignment = sizeof(void*);
> 242:     uintptr_t here = (uintptr_t)align_down(addr, smallest_possible_alignment);
> 243:     if (here == 0) {

We should use `nullptr` here not `0`:

if (here == nullptr) {

src/hotspot/share/nmt/mallocTracker.cpp line 249:

> 247:     for (; here >= end; here -= smallest_possible_alignment) {
> 248:       // JDK-8306561: cast to a MallocHeader needs to guarantee it can reside in readable memory
> 249:       if (!os::is_readable_range((uint8_t*)here, (uint8_t*)(here + sizeof(MallocHeader)))) {

Do we need the casts here? And if we do, the definition of `is_readable_range` is:

`  static bool    is_readable_range(const void* from, const void* to);
`

so cast it to `(void*)` instead.

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

PR Review: https://git.openjdk.org/jdk/pull/22885#pullrequestreview-2527850255
PR Review Comment: https://git.openjdk.org/jdk/pull/22885#discussion_r1901040928
PR Review Comment: https://git.openjdk.org/jdk/pull/22885#discussion_r1901043386


More information about the hotspot-runtime-dev mailing list