RFR: 8314114: Fix -Wconversion warnings in os code, primarily linux [v2]

Coleen Phillimore coleenp at openjdk.org
Fri Aug 11 01:03:29 UTC 2023


On Thu, 10 Aug 2023 23:34:37 GMT, Dean Long <dlong at openjdk.org> wrote:

>> Coleen Phillimore has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains eight additional commits since the last revision:
>> 
>>  - Dean's suggested changes.
>>  - Merge branch 'master' into os-conversion
>>  - Fix cgroupSubsystem_linux.cpp
>>  - Unset Wconversion for testing.
>>  - Fix signals to take int buflen, fixed return types of syscalls
>>  - Fix attachListener.cpp warnings.
>>  - change send/recv parameter type to match OS.
>>  - Fix -Wconversion warnings in os_linux.
>
> src/hotspot/os/linux/attachListener_linux.cpp line 270:
> 
>> 268: 
>> 269:   size_t off = 0;
>> 270:   size_t left = max_len;
> 
> It might be better to use ssize_t here, because of code like
> ` left -= n;`
> below.  If that underflows as unsigned then the loop won't terminate like it should.

Theoretically but we assert that n <= left.

> src/hotspot/share/runtime/os.hpp line 781:
> 
>> 779:   static void print_siginfo(outputStream* st, const void* siginfo);
>> 780:   static void print_signal_handlers(outputStream* st, char* buf, int buflen);
>> 781:   static void print_date_and_time(outputStream* st, char* buf, size_t buflen);
> 
> I understand you are trying to minimize changes, but these functions all used size_t consistently.  It seems odd to change the type of just this one function.

The reason I narrowed the types is because none of the callers pass size_t and widening dll_address_to_library_name requires platform dependent changes, and also changing the Decoder::decode() functions (or adding checked_casts<> somewhere along the way) and its subtypes.
It's not simply to minimize changes, but it is.  It's to minimize casting, or checked_casting which is also not pleasant to look at in the code everywhere.  This is why I chose passing int as buflen.  There's other functions that pass int as buflen.
Also, there's no world where we pass in a buffer that's greater than 32,000.  It's used for error reporting.

> src/hotspot/share/utilities/decoder_elf.cpp line 70:
> 
>> 68:   filepath[JVM_MAXPATHLEN - 1] = '\0';
>> 69:   int offset_in_library = -1;
>> 70:   if (!os::dll_address_to_library_name(pc, filepath, (int)sizeof(filepath), &offset_in_library)) {
> 
> How about fixing dll_address_to_library_name to use size_t like all the rest of the os:: functions?

It's painful. See above.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290803875
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290801182
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290801365


More information about the hotspot-dev mailing list