Skip to content

Commit

Permalink
8314114: Fix -Wconversion warnings in os code, primarily linux
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, dlong
  • Loading branch information
coleenp committed Aug 15, 2023
1 parent a02d65e commit 9ded868
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 128 deletions.
16 changes: 8 additions & 8 deletions src/hotspot/os/aix/attachListener_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class AixAttachListener: AllStatic {
static bool is_shutdown() { return _shutdown; }

// write the given buffer to a socket
static int write_fully(int s, char* buf, int len);
static int write_fully(int s, char* buf, size_t len);

static AixAttachOperation* dequeue();
};
Expand Down Expand Up @@ -276,7 +276,7 @@ AixAttachOperation* AixAttachListener::read_request(int s) {
// where <ver> is the protocol version (1), <cmd> is the command
// name ("load", "datadump", ...), and <arg> is an argument
int expected_str_count = 2 + AttachOperation::arg_count_max;
const int max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
const size_t max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);

char buf[max_len];
Expand All @@ -285,15 +285,15 @@ AixAttachOperation* AixAttachListener::read_request(int s) {
// Read until all (expected) strings have been read, the buffer is
// full, or EOF.

int off = 0;
int left = max_len;
size_t off = 0;
size_t left = max_len;

do {
int n;
ssize_t n;
// Don't block on interrupts because this will
// hang in the clean-up when shutting down.
n = read(s, buf+off, left);
assert(n <= left, "buffer was too small, impossible!");
assert(n <= checked_cast<ssize_t>(left), "buffer was too small, impossible!");
buf[max_len - 1] = '\0';
if (n == -1) {
return nullptr; // reset by peer or other error
Expand Down Expand Up @@ -414,9 +414,9 @@ AixAttachOperation* AixAttachListener::dequeue() {
}

// write the given buffer to the socket
int AixAttachListener::write_fully(int s, char* buf, int len) {
int AixAttachListener::write_fully(int s, char* buf, size_t len) {
do {
int n = ::write(s, buf, len);
ssize_t n = ::write(s, buf, len);
if (n == -1) {
if (errno != EINTR) return -1;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,7 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
jio_snprintf(buffer, bufferSize, "%s/core or core.%d",
p, current_process_id());

return strlen(buffer);
return checked_cast<int>(strlen(buffer));
}

bool os::start_debugging(char *buf, int buflen) {
Expand Down Expand Up @@ -3023,7 +3023,7 @@ static inline time_t get_mtime(const char* filename) {
int os::compare_file_modified_times(const char* file1, const char* file2) {
time_t t1 = get_mtime(file1);
time_t t2 = get_mtime(file2);
return t1 - t2;
return primitive_compare(t1, t2);
}

bool os::supports_map_sync() {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os/aix/os_perf_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static bool read_psinfo(const u_longlong_t& pid, psinfo_t& psinfo) {

FILE* fp;
char buf[BUF_LENGTH];
int len;
size_t len;

jio_snprintf(buf, BUF_LENGTH, "/proc/%llu/psinfo", pid);
fp = fopen(buf, "r");
Expand Down
18 changes: 9 additions & 9 deletions src/hotspot/os/bsd/attachListener_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class BsdAttachListener: AllStatic {
static int listener() { return _listener; }

// write the given buffer to a socket
static int write_fully(int s, char* buf, int len);
static int write_fully(int s, char* buf, size_t len);

static BsdAttachOperation* dequeue();
};
Expand Down Expand Up @@ -257,7 +257,7 @@ BsdAttachOperation* BsdAttachListener::read_request(int s) {
// where <ver> is the protocol version (1), <cmd> is the command
// name ("load", "datadump", ...), and <arg> is an argument
int expected_str_count = 2 + AttachOperation::arg_count_max;
const int max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
const size_t max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);

char buf[max_len];
Expand All @@ -266,21 +266,21 @@ BsdAttachOperation* BsdAttachListener::read_request(int s) {
// Read until all (expected) strings have been read, the buffer is
// full, or EOF.

int off = 0;
int left = max_len;
size_t off = 0;
size_t left = max_len;

do {
int n;
ssize_t n;
RESTARTABLE(read(s, buf+off, left), n);
assert(n <= left, "buffer was too small, impossible!");
assert(n <= checked_cast<ssize_t>(left), "buffer was too small, impossible!");
buf[max_len - 1] = '\0';
if (n == -1) {
return nullptr; // reset by peer or other error
}
if (n == 0) {
break;
}
for (int i=0; i<n; i++) {
for (ssize_t i=0; i<n; i++) {
if (buf[off+i] == 0) {
// EOS found
str_count++;
Expand Down Expand Up @@ -383,9 +383,9 @@ BsdAttachOperation* BsdAttachListener::dequeue() {
}

// write the given buffer to the socket
int BsdAttachListener::write_fully(int s, char* buf, int len) {
int BsdAttachListener::write_fully(int s, char* buf, size_t len) {
do {
int n = ::write(s, buf, len);
ssize_t n = ::write(s, buf, len);
if (n == -1) {
if (errno != EINTR) return -1;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2208,9 +2208,9 @@ static inline struct timespec get_mtime(const char* filename) {
int os::compare_file_modified_times(const char* file1, const char* file2) {
struct timespec filetime1 = get_mtime(file1);
struct timespec filetime2 = get_mtime(file2);
int diff = filetime1.tv_sec - filetime2.tv_sec;
int diff = primitive_compare(filetime1.tv_sec, filetime2.tv_sec);
if (diff == 0) {
return filetime1.tv_nsec - filetime2.tv_nsec;
diff = primitive_compare(filetime1.tv_nsec, filetime2.tv_nsec);
}
return diff;
}
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/os/linux/attachListener_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class LinuxAttachListener: AllStatic {
static int listener() { return _listener; }

// write the given buffer to a socket
static int write_fully(int s, char* buf, int len);
static int write_fully(int s, char* buf, size_t len);

static LinuxAttachOperation* dequeue();
};
Expand Down Expand Up @@ -257,7 +257,7 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
// where <ver> is the protocol version (1), <cmd> is the command
// name ("load", "datadump", ...), and <arg> is an argument
int expected_str_count = 2 + AttachOperation::arg_count_max;
const int max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
const size_t max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);

char buf[max_len];
Expand All @@ -266,21 +266,21 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
// Read until all (expected) strings have been read, the buffer is
// full, or EOF.

int off = 0;
int left = max_len;
size_t off = 0;
size_t left = max_len;

do {
int n;
ssize_t n;
RESTARTABLE(read(s, buf+off, left), n);
assert(n <= left, "buffer was too small, impossible!");
assert(n <= checked_cast<ssize_t>(left), "buffer was too small, impossible!");
buf[max_len - 1] = '\0';
if (n == -1) {
return nullptr; // reset by peer or other error
}
if (n == 0) {
break;
}
for (int i=0; i<n; i++) {
for (ssize_t i=0; i<n; i++) {
if (buf[off+i] == 0) {
// EOS found
str_count++;
Expand Down Expand Up @@ -383,7 +383,7 @@ LinuxAttachOperation* LinuxAttachListener::dequeue() {
}

// write the given buffer to the socket
int LinuxAttachListener::write_fully(int s, char* buf, int len) {
int LinuxAttachListener::write_fully(int s, char* buf, size_t len) {
do {
ssize_t n = ::write(s, buf, len);
if (n == -1) {
Expand Down

1 comment on commit 9ded868

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.