Skip to content
3 changes: 1 addition & 2 deletions src/hotspot/os/aix/attachListener_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,8 @@ void AttachListener::vm_start() {
struct stat st;
int ret;

int n = os::snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
os::snprintf_checked(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
os::get_temp_directory(), os::current_process_id());
assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");

RESTARTABLE(::stat(fn, &st), ret);
if (ret == 0) {
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/os/posix/attachListener_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,8 @@ void AttachListener::vm_start() {
struct stat st;
int ret;

int n = os::snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
os::snprintf_checked(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
os::get_temp_directory(), os::current_process_id());
assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");

RESTARTABLE(::stat(fn, &st), ret);
if (ret == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/shared/satbMarkQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void SATBMarkQueueSet::print_all(const char* msg) {
_qset(qset), _buffer(buffer) {}

virtual void do_thread(Thread* t) {
os::snprintf_checked(_buffer, SATB_PRINTER_BUFFER_SIZE, "Thread: %s", t->name());
(void) os::snprintf(_buffer, SATB_PRINTER_BUFFER_SIZE, "Thread: %s", t->name());
_qset->satb_queue_for_thread(t).print(_buffer);
}
} closure(this, buffer);
Expand Down
11 changes: 8 additions & 3 deletions src/hotspot/share/runtime/os.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,17 @@ class os: AllStatic {

// Performs vsnprintf and asserts the result is non-negative (so there was not
// an encoding error or any other kind of usage error).
[[nodiscard]] static int vsnprintf(char* buf, size_t len, const char* fmt, va_list args) ATTRIBUTE_PRINTF(3, 0);
[[nodiscard]]
ATTRIBUTE_PRINTF(3, 0)
static int vsnprintf(char* buf, size_t len, const char* fmt, va_list args);
// Delegates to vsnprintf.
[[nodiscard]] static int snprintf(char* buf, size_t len, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);
[[nodiscard]]
ATTRIBUTE_PRINTF(3, 4)
static int snprintf(char* buf, size_t len, const char* fmt, ...);

// Delegates to snprintf and asserts that the output was not truncated.
static void snprintf_checked(char* buf, size_t len, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);
ATTRIBUTE_PRINTF(3, 4)
static void snprintf_checked(char* buf, size_t len, const char* fmt, ...);

// Get host name in buffer provided
static bool get_host_name(char* buf, size_t buflen);
Expand Down