On Wed, 16 Nov 2022 06:43:29 GMT, Xue-Lei Andrew Fan <[email protected]> wrote:
>> src/hotspot/share/utilities/utf8.cpp line 521:
>>
>>> 519: } else {
>>> 520: if (p + 6 >= end) break; // string is truncated
>>> 521: os::snprintf(p, 7, "\\u%04x", c);
>>
>> This should be 6, or? We have 6 characters left before end, assuming end is
>> exclusive.
>>
>> Also, maybe use a named constant?
>
> If 6 is used, there is a output truncated warning and only 5 characters are
> filed actually. The terminating null/zero is counted in, I think. To make
> it easier to read, I added a comment.
For snprintf, all bytes written to the buffer (including the terminating \0)
are counted. You have 6 bytes for character encoding ("\uxxxx") and one byte
for \0. Code is correct.
-------------
PR: https://git.openjdk.org/jdk/pull/11115