--- a/src/hotspot/os/posix/os_posix.cpp Thu Feb 21 15:17:42 2019 -0800
+++ b/src/hotspot/os/posix/os_posix.cpp Thu Feb 21 16:56:06 2019 -0800
@@ -180,13 +180,14 @@
const char name_template[] = "/jvmheap.XXXXXX";
- char *fullname = (char*)os::malloc((strlen(dir) + strlen(name_template) + 1), mtInternal);
+ size_t fullname_len = strlen(dir) + strlen(name_template);
+ char *fullname = (char*)os::malloc(fullname_len + 1, mtInternal);
if (fullname == NULL) {
vm_exit_during_initialization(err_msg("Malloc failed during creation of backing file for heap (%s)", os::strerror(errno)));
return -1;
}
- (void)strncpy(fullname, dir, strlen(dir)+1);
- (void)strncat(fullname, name_template, strlen(name_template));
+ int n = snprintf(fullname, fullname_len + 1, "%s%s", dir, name_template);
+ assert((size_t)n == fullname_len, "Unexpected number of characters in string");
os::native_path(fullname);