RFR: 8338257: UTF8 lengths should be size_t not int [v5]

Dean Long dlong at openjdk.org
Tue Aug 27 16:54:07 UTC 2024


On Tue, 27 Aug 2024 12:10:36 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> src/hotspot/share/utilities/utf8.cpp line 127:
>> 
>>> 125:     prev = c;
>>> 126:   }
>>> 127:   return checked_cast<int>(num_chars);
>> 
>> Ideally, this function would return size_t.
>
> Why? I think that would have a large flow on effect. And this length does fit in an int.

The worse case is len == SIZE_MAX and therefore num_chars == SIZE_MAX, which won't fit in an int.  If we say this will never happen because current callers never use sizes bigger than int, that makes the code fragile against scenarios where a developer might add a new caller.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20560#discussion_r1733226733


More information about the serviceability-dev mailing list