src/hotspot/os/windows/os_windows.cpp
changeset 53882 ca682d9d8db5
parent 53687 e439ec989141
child 53886 e94ed0236046
--- a/src/hotspot/os/windows/os_windows.cpp	Thu Feb 21 15:17:42 2019 -0800
+++ b/src/hotspot/os/windows/os_windows.cpp	Thu Feb 21 16:56:06 2019 -0800
@@ -2970,14 +2970,15 @@
 int os::create_file_for_heap(const char* dir) {
 
   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);