RFR: 8334599: Improve code from JDK-8302671

Julian Waters jwaters at openjdk.org
Fri Jun 21 04:37:09 UTC 2024


On Thu, 20 Jun 2024 08:29:39 GMT, Julian Waters <jwaters at openjdk.org> wrote:

> In [JDK-8302671](https://bugs.openjdk.org/browse/JDK-8302671) I fixed a memmove decay bug by rewriting a sizeof on an array to an explicit size of 256, but this is a bit of a band aid fix. It's come to my attention that in C++, one can pass an array by reference, which causes sizeof to work correctly on an array and has the added bonus of enforcing an array of that size on the arguments passed to that method. I've reverted my change from 8302671 and instead explicitly made kstate an array reference so that sizeof works on the array as expected, and that the array size can be explicitly set in the array brackets
> 
> Verification: https://godbolt.org/z/Ezj76eWWY and GitHub Actions

Yes, it doesn't change any existing behaviour, it's just a more robust way of expressing what was already there before, so it should be harmless. I'm not sure I follow your other concern about it being a mixture though, I checked and this method is static and only used in this file, and the few callsites that do use it all initialize their arrays to KB_STATE_SIZE. Do you mean getting rid of the hardcoded 256 in this method's array parameter? The other thing about passing an array by reference means if the caller doesn't get the array size exactly right, it will not result in a silent bug, it is an immediate compilation error, so if the caller passes a shorter array it will simply refuse to compile, which is likely what we want here

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

PR Comment: https://git.openjdk.org/jdk/pull/19798#issuecomment-2181982129


More information about the client-libs-dev mailing list