RFR: 8314114: Fix -Wconversion warnings in os code, primarily linux
Coleen Phillimore
coleenp at openjdk.org
Thu Aug 10 20:35:28 UTC 2023
On Thu, 10 Aug 2023 18:58:19 GMT, Dean Long <dlong at openjdk.org> wrote:
>> This change fixes various -Wconversion warnings from files in the os directories and related, widening types or adding checked_cast<> where narrowing.
>> Tested with tier1 on linux/macosx/windows and tier1-4 on linux-x64-debug, windows-x64-debug.
>
> src/hotspot/os/aix/attachListener_aix.cpp line 289:
>
>> 287:
>> 288: ssize_t off = 0;
>> 289: ssize_t left = max_len;
>
> Doesn't this cause a sign-conversion warning because read expects size_t?
I don't have -Wsign-conversion on, only -Wconversion, so I don't get -Wsign-conversion warnings for hotspot files. This same change is made to os/linux/attachListener_linux.cpp. Suggestions how to fix?
> src/hotspot/os/aix/os_aix.cpp line 3026:
>
>> 3024: time_t t1 = get_mtime(file1);
>> 3025: time_t t2 = get_mtime(file2);
>> 3026: return checked_cast<int>(t1 - t2);
>
> It seems like checked_cast<> could fail if the file has a bad timestamp far in the future.
> Suggestion:
>
> return primitive_compare(t1, t2);
This is a good idea to use primitive_compare.
> src/hotspot/os/linux/os_linux.cpp line 1604:
>
>> 1602:
>> 1603: Elf32_Ehdr elf_head;
>> 1604: size_t diag_msg_max_length=ebuflen-strlen(ebuf);
>
> Underflow will result in very large unsigned number. Do we need helper functions for unsigned math that checks for underflow/overflow?
I could have just checked_cast<int>(strlen(ebuf)); since it's 100% unlikely that the buffer is 2,147,483,647 chars long. I don't understand why strlen returns a size_t tbh.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290627670
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290629641
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290644112
More information about the hotspot-dev
mailing list