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

Dean Long dlong at openjdk.org
Thu Aug 10 19:25:31 UTC 2023


On Thu, 10 Aug 2023 15:22:07 GMT, Coleen Phillimore <coleenp 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?

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);

src/hotspot/os/bsd/os_bsd.cpp line 2211:

> 2209:   struct timespec filetime1 = get_mtime(file1);
> 2210:   struct timespec filetime2 = get_mtime(file2);
> 2211:   time_t diff = filetime1.tv_sec - filetime2.tv_sec;

Is time_t guaranteed to be signed?
Suggestion:

  int diff = primitive_compare(filetime1.tv_sec, filetime2.tv_sec);

src/hotspot/os/bsd/os_bsd.cpp line 2213:

> 2211:   time_t diff = filetime1.tv_sec - filetime2.tv_sec;
> 2212:   if (diff == 0) {
> 2213:     diff = filetime1.tv_nsec - filetime2.tv_nsec;

Suggestion:

    diff = primitive_compare(filetime1.tv_nsec, filetime2.tv_nsec);

src/hotspot/os/bsd/os_bsd.cpp line 2215:

> 2213:     diff = filetime1.tv_nsec - filetime2.tv_nsec;
> 2214:   }
> 2215:   return checked_cast<int>(diff);

Suggestion:

  return diff;

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290561229
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290567457
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290569988
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290570883
PR Review Comment: https://git.openjdk.org/jdk/pull/15229#discussion_r1290571285


More information about the hotspot-dev mailing list