Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1557,6 +1557,7 @@ void os::jvm_path(char *buf, jint buflen) {
}

char dli_fname[MAXPATHLEN];
dli_fname[0] = '\0';
bool ret = dll_address_to_library_name(
CAST_FROM_FN_PTR(address, os::jvm_path),
dli_fname, sizeof(dli_fname), NULL);
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,7 @@ void os::jvm_path(char *buf, jint buflen) {
}

char dli_fname[MAXPATHLEN];
dli_fname[0] = '\0';
bool ret = dll_address_to_library_name(
CAST_FROM_FN_PTR(address, os::jvm_path),
dli_fname, sizeof(dli_fname), NULL);
Expand Down
6 changes: 4 additions & 2 deletions src/hotspot/share/prims/nativeLookup.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -434,8 +434,10 @@ void* NativeLookup::dll_load(const methodHandle& method) {
address current_entry = method->native_function();

char dll_name[JVM_MAXPATHLEN];
dll_name[0] = '\0';
int offset;
if (os::dll_address_to_library_name(current_entry, dll_name, sizeof(dll_name), &offset)) {
bool ret = os::dll_address_to_library_name(current_entry, dll_name, sizeof(dll_name), &offset);
if (ret && dll_name[0] != '\0') {
char ebuf[32];
return os::dll_load(dll_name, ebuf, sizeof(ebuf));
}
Expand Down
6 changes: 4 additions & 2 deletions src/hotspot/share/runtime/frame.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -540,9 +540,11 @@ void frame::print_C_frame(outputStream* st, char* buf, int buflen, address pc) {
int offset;
bool found;

if (buf == NULL || buflen < 1) return;
Copy link
Member

Choose a reason for hiding this comment

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

Can this not just be an assert: buf != NULL && buflen > 0 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi David, I think a return would be clearer but an assert is "better than nothing" .

Best regards, Matthias

Copy link
Contributor

Choose a reason for hiding this comment

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

With an assert, you assume this is a "cannot occur error". You should be pretty sure to have good test coverage to find all "illegal invocations" before letting a release build escape into the wild.

Copy link
Member

Choose a reason for hiding this comment

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

+1 for the assert.
If you are worried about release, combine assert with release check:

assert(buf && buflen > 1, "sanity");
if (buf == NULL || buflen < 1) return;

Its what I usually do if I want to be super thorough.
Sorry for the bikeshedding :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi Thomas, I like your suggestion ; David are you fine with it ?

// libname
buf[0] = '\0';
found = os::dll_address_to_library_name(pc, buf, buflen, &offset);
if (found) {
if (found && buf[0] != '\0') {
// skip directory names
const char *p1, *p2;
p1 = buf;
Expand Down