RFR: 8338257: UTF8 lengths should be size_t not int [v5]
Coleen Phillimore
coleenp at openjdk.org
Mon Aug 26 23:44:06 UTC 2024
On Mon, 19 Aug 2024 23:08:35 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> src/hotspot/share/classfile/javaClasses.cpp line 639:
>>
>>> 637: if (length == 0) {
>>> 638: return 0;
>>> 639: }
>>
>> Maybe assert length > 0 here?
>
> Why "> 0" ?
Because length is an in which could be negative but you're passing it to size_t. -Wsign-conversion might complain because you're changing signs. I guess you know from context that it's a positive number, so ok.
>> src/hotspot/share/prims/jni.cpp line 2226:
>>
>>> 2224: HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY(env, string);
>>> 2225: oop java_string = JNIHandles::resolve_non_null(string);
>>> 2226: jsize ret = java_lang_String::utf8_length_as_int(java_string);
>>
>> So the spec says that this should be jsize (signed int), which is why this is, right?
>
> Yes. Hence the other change to add a new JNI API.
Ok.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20560#discussion_r1731939815
PR Review Comment: https://git.openjdk.org/jdk/pull/20560#discussion_r1731940575
More information about the serviceability-dev
mailing list