On Thu, 16 Feb 2023 17:56:54 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:

> Does anybody know how this was found, by some tool or compiler warning?

It was found by gcc, which will raise a noisy alert of 
`-Wsizeof-array-argument` and `-Wsizeof-pointer-memaccess` when compiling


awt_Component.cpp:3402:38: error: 'sizeof' on array function parameter 'kstate' 
will return size of 'BYTE*' {aka 'unsigned char
'} [-Werror=sizeof-array-argument]
 3402 |     memmove(tmpState, kstate, sizeof(kstate));
      |                                     ~^~~~~~~
awt_Component.cpp:3399:21: note: declared here
 3399 | resetKbdState( BYTE kstate[256]) {
      |                ~~~~~^~~~~~~~~~~
awt_Component.cpp:3402:31: error: argument to 'sizeof' in 'void* memmove(void*, 
const void*, size_t)' call is the same expression as the source; did you mean 
to provide an explicit length? [-Werror=sizeof-pointer-memaccess]
 3402 |     memmove(tmpState, kstate, sizeof(kstate));
      |                               ^~~~~~~~~~~~~~
cc1plus.exe: all warnings being treated as errors


Also related:
https://stackoverflow.com/questions/6567742/passing-an-array-as-an-argument-to-a-function-in-c
https://stackoverflow.com/questions/14309136/passing-arrays-to-function-in-c

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

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

Reply via email to