RFR: 8314114: Fix -Wconversion warnings in os code, primarily linux [v2]
David Holmes
dholmes at openjdk.org
Tue Aug 15 01:08:21 UTC 2023
On Mon, 14 Aug 2023 19:45:53 GMT, Dean Long <dlong at openjdk.org> wrote:
>> 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`.
>
> Isn't the compiler complaining because the comparison will be done as unsigned, and a negative value turns into a huge unsigned value? To do a loss-less compare, both sides would need to be widened to a common signed type that can represent either side, like __int128_t. There's probably an equivalent way to do it with 64-bit values, but I think it would involve more than one compare.
Yes that is the problem. My point is that the type system leads you into that problem even though you are trying to use the "correct" types.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1294096269
More information about the hotspot-dev
mailing list