src/hotspot/share/services/diagnosticArgument.cpp
changeset 53882 ca682d9d8db5
parent 50600 8e17fffa0a4b
child 53908 45a23c64d0f6
--- a/src/hotspot/share/services/diagnosticArgument.cpp	Thu Feb 21 15:17:42 2019 -0800
+++ b/src/hotspot/share/services/diagnosticArgument.cpp	Thu Feb 21 16:56:06 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -179,9 +179,9 @@
   if (str == NULL) {
     _value = NULL;
   } else {
-    _value = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
-    strncpy(_value, str, len);
-    _value[len] = 0;
+    _value = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
+    int n = snprintf(_value, len + 1, "%.*s", (int)len, str);
+    assert((size_t)n <= len, "Unexpected number of characters in string");
   }
 }