src/hotspot/share/utilities/xmlstream.cpp
changeset 53882 ca682d9d8db5
parent 49361 1956d0ec092a
child 53908 45a23c64d0f6
--- a/src/hotspot/share/utilities/xmlstream.cpp	Thu Feb 21 15:17:42 2019 -0800
+++ b/src/hotspot/share/utilities/xmlstream.cpp	Thu Feb 21 16:56:06 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -353,11 +353,15 @@
   guarantee(format_len + 10 < sizeof(buffer), "bigger format buffer");
   const char* kind = format;
   const char* kind_end = strchr(kind, ' ');
-  size_t kind_len = (kind_end != NULL) ? (kind_end - kind) : format_len;
-  strncpy(buffer, kind, kind_len);
-  strcpy(buffer + kind_len, "_done");
+  size_t kind_len;
   if (kind_end != NULL) {
-    strncat(buffer, format + kind_len, sizeof(buffer) - (kind_len + 5 /* _done */) - 1);
+    kind_len = kind_end - kind;
+    int n = snprintf(buffer, sizeof(buffer), "%.*s_done", (int)kind_len, kind);
+    assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
+  } else {
+    kind_len = format_len;
+    int n = snprintf(buffer, sizeof(buffer), "%s_done%s", kind, kind + kind_len);
+    assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
   }
   // Output the trailing event with the timestamp.
   va_begin_elem(buffer, ap);