On Mon, 17 Jul 2023 20:54:25 GMT, Roger Riggs <rri...@openjdk.org> wrote:
>> 温绍锦 has updated the pull request incrementally with one additional commit >> since the last revision: >> >> Integer/Long toString test against compact strings >> >> Co-authored-by: liach <li...@users.noreply.github.com> > > src/java.base/share/classes/java/lang/Long.java line 559: > >> 557: Unsafe.ARRAY_BYTE_BASE_OFFSET + charPos, >> 558: Integer.PACKED_DIGITS[(int)((q * 100) - i)], >> 559: false); > > Add the array bound check for the store of the characters. I added assert with reference to the implementation of StringUTF16#putChar, is this safe enough? > src/java.base/share/classes/java/lang/Long.java line 584: > >> 582: Unsafe.ARRAY_BYTE_BASE_OFFSET + charPos, >> 583: Integer.PACKED_DIGITS[-i2], >> 584: false); > > Replace the implicit array bounds check with an explicit array index check if > using Unsafe. I added assert with reference to the implementation of StringUTF16#putChar, is this safe enough? > src/java.base/share/classes/java/lang/StringUTF16.java line 1595: > >> 1593: PACKED_DIGITS_UTF16[-i]); >> 1594: } else { >> 1595: putChar(buf, --charPos, '0' - i); > > Ditto add explicit array bounds check when using Unsafe, especially since the > method is used outside of the source file. Here and in the uses of Unsafe > below. I added assert with reference to the implementation of StringUTF16#putChar, is this safe enough? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14699#discussion_r1269188797 PR Review Comment: https://git.openjdk.org/jdk/pull/14699#discussion_r1269188920 PR Review Comment: https://git.openjdk.org/jdk/pull/14699#discussion_r1269189024