On Fri, 24 Jan 2025 09:53:43 GMT, SendaoYan <s...@openjdk.org> wrote:

> Hi all,
> This PR fix a undefined behaviour in 'CollisionsReceiveDifferentIndexes' 
> testcase 
> locate in 'test/hotspot/gtest/nmt/test_nmt_nativecallstackstorage.cpp' file 
> when call `NativeCallStack::NativeCallStack` function. Before this PR, 
> 'CollisionsReceiveDifferentIndexes' test allocate 4 type variable `i` and 
> then pass the address `&i`, but in 'NativeCallStack' function read the 
> pointer as 8 types, so the AddressSanitizer report "Memory access partially 
> overflows variable i". This PR change the variable `i` to `size_t` to avoid 
> this undefined behaviour.
> Change has been verified locally, test-fix only, no risk.
> 
> Below code snippet can reproduce the same issue:
> 
> 
> #include <stdio.h>
> typedef unsigned char u_char;
> typedef u_char*       address;
> int main()
> {
>   int i = 0;
>   address* pc = (address*)(&i);
>   address _stack = pc[0];
>   printf("_stack = %p\n", _stack);
>   return 0;
> }
> 
> 
> Reproduce command:
> 
> clang -g3 -Wall -Wextra -fsanitize=address -fsanitize=leak 
> -fsanitize=undefined partially-overflows.c && ./a.out

Thanks all for the reviews.

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

PR Comment: https://git.openjdk.org/jdk/pull/23294#issuecomment-2623885264

Reply via email to