On Thu, 16 Feb 2023 15:33:51 GMT, Julian Waters <[email protected]> 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