# HG changeset patch
# User stuefe
# Date 1549941248 0
#      Tue Feb 12 03:14:08 2019 +0000
# Node ID 9bbf02572dc114e85829673a7cdaffa482115f42
# Parent  cfb34db6589e222d34e5b736b99ed4f69c261c4f
# Adapted to apply against version of JDK-8076475 in 8u272-b04 
8076475, PR3696: Misuses of strncpy/strncat
Summary: Various small fixes around strncpy and strncat
Reviewed-by: dsamersoff, coleenp

diff -Nru openjdk.orig/hotspot/src/share/vm/compiler/compilerOracle.cpp openjdk/hotspot/src/share/vm/compiler/compilerOracle.cpp
--- openjdk.orig/hotspot/src/share/vm/compiler/compilerOracle.cpp	2019-04-16 16:03:42.787215846 +0100
+++ openjdk/hotspot/src/share/vm/compiler/compilerOracle.cpp	2019-04-16 16:05:31.445511866 +0100
@@ -647,9 +647,7 @@
       // so read integer and fraction part of double value separately.
       if (sscanf(line, "%*[ \t]%255[0-9]%*[ /\t]%255[0-9]%n", buffer[0], buffer[1], &bytes_read) == 2) {
         char value[512] = "";
-        strncat(value, buffer[0], 255);
-        strcat(value, ".");
-        strncat(value, buffer[1], 255);
+        jio_snprintf(value, sizeof(value), "%s.%s", buffer[0], buffer[1]);
         total_bytes_read += bytes_read;
         return add_option_string(c_name, c_match, m_name, m_match, signature, flag, atof(value));
       } else {
diff --git openjdk.orig/hotspot/src/share/vm/runtime/arguments.cpp openjdk/hotspot/src/share/vm/runtime/arguments.cpp
--- openjdk.orig/hotspot/src/share/vm/runtime/arguments.cpp
+++ openjdk/hotspot/src/share/vm/runtime/arguments.cpp
@@ -3476,7 +3476,7 @@
       src ++;
     }
 
-    char* copy = os::strdup(src, mtInternal);
+    char* copy = os::strdup_check_oom(src, mtInternal);
 
     // trim all trailing empty paths
     for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
@@ -3862,7 +3862,7 @@
         jvm_path, os::file_separator());
     }
   } else {
-    shared_archive_path = os::strdup(SharedArchiveFile, mtInternal);
+    shared_archive_path = os::strdup_check_oom(SharedArchiveFile, mtInternal);
   }
   return shared_archive_path;
 }
