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

Dean Long dlong at openjdk.org
Thu Aug 10 21:36:28 UTC 2023


On Thu, 10 Aug 2023 20:07:47 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

>> 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?

checked_cast<size_t>() where necessary, unfortunately.

>> 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.

I was more concerned about missing a buffer overflow, resulting in strlen(ebuf) > ebuflen.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290694809
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290696399


More information about the hotspot-dev mailing list