8218935: Make jfr strncpy uses GCC 8.x friendly
authormikael
Thu, 14 Feb 2019 15:17:03 -0800
changeset 53762 65deccd64f3a
parent 53761 e77095ade618
child 53763 93b42eb5f3fc
8218935: Make jfr strncpy uses GCC 8.x friendly Reviewed-by: clanger
src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadGroup.cpp
src/hotspot/share/jfr/recorder/repository/jfrChunkState.cpp
src/hotspot/share/jfr/recorder/repository/jfrRepository.cpp
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadGroup.cpp	Thu Feb 14 15:12:17 2019 -0800
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadGroup.cpp	Thu Feb 14 15:17:03 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 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
@@ -238,9 +238,8 @@
   assert(_thread_group_name == NULL, "invariant");
   if (tgname != NULL) {
     size_t len = strlen(tgname);
-    _thread_group_name = JfrCHeapObj::new_array<char>(len+1);
-    strncpy(_thread_group_name, tgname, len);
-    _thread_group_name[len] = '\0';
+    _thread_group_name = JfrCHeapObj::new_array<char>(len + 1);
+    strncpy(_thread_group_name, tgname, len + 1);
   }
 }
 
--- a/src/hotspot/share/jfr/recorder/repository/jfrChunkState.cpp	Thu Feb 14 15:12:17 2019 -0800
+++ b/src/hotspot/share/jfr/recorder/repository/jfrChunkState.cpp	Thu Feb 14 15:17:03 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -100,8 +100,7 @@
   assert(path != NULL, "invariant");
   const size_t path_len = strlen(path);
   char* new_path = JfrCHeapObj::new_array<char>(path_len + 1);
-  strncpy(new_path, path, path_len);
-  new_path[path_len] = '\0';
+  strncpy(new_path, path, path_len + 1);
   return new_path;
 }
 
--- a/src/hotspot/share/jfr/recorder/repository/jfrRepository.cpp	Thu Feb 14 15:12:17 2019 -0800
+++ b/src/hotspot/share/jfr/recorder/repository/jfrRepository.cpp	Thu Feb 14 15:17:03 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
@@ -209,8 +209,7 @@
   if (entry_name == NULL) {
     return NULL;
   }
-  strncpy(entry_name, entry, entry_len);
-  entry_name[entry_len] = '\0';
+  strncpy(entry_name, entry, entry_len + 1);
   const char* const fully_qualified_path_entry = fully_qualified(entry_name);
   if (NULL == fully_qualified_path_entry) {
     return NULL;
@@ -332,8 +331,7 @@
     if (NULL == emergency_dump_path) {
       return NULL;
     }
-    strncpy(emergency_dump_path, buffer, emergency_filename_length);
-    emergency_dump_path[emergency_filename_length] = '\0';
+    strncpy(emergency_dump_path, buffer, emergency_filename_length + 1);
   }
   return emergency_dump_path;
 }
@@ -407,8 +405,7 @@
   if (_path == NULL) {
     return false;
   }
-  strncpy(_path, path, path_len);
-  _path[path_len] = '\0';
+  strncpy(_path, path, path_len + 1);
   return true;
 }