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

SendaoYan syan at openjdk.org
Wed Feb 5 12:33:59 UTC 2025


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 PR do not change the original logic but eliminate the undefined behaviour in code.

Change has been verified locally, test-fix only, no risk.

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

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

Changes: https://git.openjdk.org/jdk/pull/23462/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=23462&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8349465
  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/23462.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/23462/head:pull/23462

PR: https://git.openjdk.org/jdk/pull/23462


More information about the hotspot-runtime-dev mailing list