RFR: 8302671: libawt has a memmove decay error

Kevin Rushforth kcr at openjdk.org
Thu Feb 16 16:44:27 UTC 2023


On Thu, 16 Feb 2023 15:33:51 GMT, Julian Waters <jwaters at openjdk.org> wrote:

> In libawt, the size parameter is issued by a sizeof on an array, which as expected decays into a pointer and breaks the cleanup code by giving the incorrect size

I just checked, and he is correct. In a function declaration, the array is treated as a pointer, so `sizeof(arr)` is the same as `sizeof(BYTE *)`. This even generates a compiler warning on gcc:


#include <stdio.h>

typedef unsigned char BYTE;

void do_check(BYTE arr[256]) {
    printf("check: sizeof(arr) = %ld\n", sizeof(arr));
}

int main(int argc, char** argv) {
    BYTE arr[100];
    printf("main: sizeof(arr) = %ld\n", sizeof(arr));
    do_check(arr);
}



$ cc -o foo foo.c
foo.c: In function 'do_check':
foo.c:6:48: warning: 'sizeof' on array function parameter 'arr' will return size of 'BYTE * {aka unsigned char *}' [-Wsizeof-array-argument]
     printf("check: sizeof(arr) = %ld\n", sizeof(arr));



$ ./foo
main: sizeof(arr) = 100
check: sizeof(arr) = 8

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

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



More information about the client-libs-dev mailing list