RFR: 8349465: [UBSAN] test_os_reserve_between.cpp reported applying non-zero offset to null pointer

Martin Doerr mdoerr at openjdk.org
Thu Feb 6 12:08:13 UTC 2025


On Wed, 5 Feb 2025 12:29:23 GMT, SendaoYan <syan at openjdk.org> wrote:

> Hi all,
> Test function `os_attempt_reserve_memory_between_combos_vm_Test::TestBody()` in "test/hotspot/gtest/runtime/test_os_reserve_between.cpp" file reported "applying non-zero offset 4096 to null pointer" by UndefinedBehaviorSanitizer. The var `min` cast from 0 to pointer and then apply non-zero offset `range_size` is undefined behavior.
> 
> This PR cast pointer `min` to uintptr_t before add the offset `range_size`, and the cast back to pointer. This solution similar to [JDK-8346714](https://github.com/openjdk/jdk/pull/22848). This PR do not change the original logic but eliminate the undefined behaviour in code.
> 
> Change has been verified locally, test-fix only, no risk.

LGTM.

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

Marked as reviewed by mdoerr (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/23462#pullrequestreview-2598481293


More information about the hotspot-runtime-dev mailing list