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

David Holmes dholmes at openjdk.org
Mon Aug 14 02:24:58 UTC 2023


On Sat, 12 Aug 2023 12:54:21 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

>> I'm curious, who is warning here? Is this a static code analysis? Since I don't think Oracle builds AIX, right?
>
> The AIX code is a copy of the linux code.  I got a sign conversion warning on the linux code. 
> 
> src/hotspot/os/linux/attachListener_linux.cpp:275:14: warning: comparison of integer expressions of different signedness: 'ssize_t' {aka 'long int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
>   275 |     assert(n <= left, "buffer was too small, impossible!");
>       |            ~~^~~~~~~

This is an example of how the basic integer type system is broken. You define size variables as `size_t` but then get `ssize_t` back from functions like `read`, and then you get warnings if you combine them in particular ways. In this particular case I don't even understand the conversion warning as semantically a maximum `ssize_t` must be < the maximum `size_t` so where is the loss? It also seems to me that the strictly correct way to address this would be to ensure the `ssize_t` variable is not -1 and then cast it to `size_t`, rather than downcasting the `size_t` variable to `ssize_t`.

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

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


More information about the hotspot-dev mailing list