static size_t get_dump_directory() {
const char* dump_path = JfrEmergencyDump::get_dump_path();
if (*dump_path == '\0') {
if (os::get_current_directory(_path_buffer, sizeof(_path_buffer)) == NULL) {
return 0;
}
} else {
strcpy(_path_buffer, dump_path);
}
const size_t path_len = strlen(_path_buffer);
const int result = jio_snprintf(_path_buffer + path_len,
sizeof(_path_buffer),
"%s",
os::file_separator());
return (result == -1) ? 0 : strlen(_path_buffer);
}
Since the start address of the char buffer passing to jio_snprintf is offset by path_len, the length of the buffer (second arg to jio_snprintf) should be adjusted according.
const char* dump_path = JfrEmergencyDump::get_dump_path();
if (*dump_path == '\0') {
if (os::get_current_directory(_path_buffer, sizeof(_path_buffer)) == NULL) {
return 0;
}
} else {
strcpy(_path_buffer, dump_path);
}
const size_t path_len = strlen(_path_buffer);
const int result = jio_snprintf(_path_buffer + path_len,
sizeof(_path_buffer),
"%s",
os::file_separator());
return (result == -1) ? 0 : strlen(_path_buffer);
}
Since the start address of the char buffer passing to jio_snprintf is offset by path_len, the length of the buffer (second arg to jio_snprintf) should be adjusted according.