提交 e6acda66 编写于 作者: M mikael

8218935: Make jfr strncpy uses GCC 8.x friendly

Reviewed-by: clanger
上级 5d53bb0d
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -238,9 +238,8 @@ void JfrThreadGroup::JfrThreadGroupEntry::set_thread_group_name(const char* tgna ...@@ -238,9 +238,8 @@ void JfrThreadGroup::JfrThreadGroupEntry::set_thread_group_name(const char* tgna
assert(_thread_group_name == NULL, "invariant"); assert(_thread_group_name == NULL, "invariant");
if (tgname != NULL) { if (tgname != NULL) {
size_t len = strlen(tgname); size_t len = strlen(tgname);
_thread_group_name = JfrCHeapObj::new_array<char>(len+1); _thread_group_name = JfrCHeapObj::new_array<char>(len + 1);
strncpy(_thread_group_name, tgname, len); strncpy(_thread_group_name, tgname, len + 1);
_thread_group_name[len] = '\0';
} }
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -99,8 +99,7 @@ static char* copy_path(const char* path) { ...@@ -99,8 +99,7 @@ static char* copy_path(const char* path) {
assert(path != NULL, "invariant"); assert(path != NULL, "invariant");
const size_t path_len = strlen(path); const size_t path_len = strlen(path);
char* new_path = JfrCHeapObj::new_array<char>(path_len + 1); char* new_path = JfrCHeapObj::new_array<char>(path_len + 1);
strncpy(new_path, path, path_len); strncpy(new_path, path, path_len + 1);
new_path[path_len] = '\0';
return new_path; return new_path;
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -209,8 +209,7 @@ const char* const RepositoryIterator::filter(const char* entry) const { ...@@ -209,8 +209,7 @@ const char* const RepositoryIterator::filter(const char* entry) const {
if (entry_name == NULL) { if (entry_name == NULL) {
return NULL; return NULL;
} }
strncpy(entry_name, entry, entry_len); strncpy(entry_name, entry, entry_len + 1);
entry_name[entry_len] = '\0';
const char* const fully_qualified_path_entry = fully_qualified(entry_name); const char* const fully_qualified_path_entry = fully_qualified(entry_name);
if (NULL == fully_qualified_path_entry) { if (NULL == fully_qualified_path_entry) {
return NULL; return NULL;
...@@ -332,8 +331,7 @@ static const char* create_emergency_dump_path() { ...@@ -332,8 +331,7 @@ static const char* create_emergency_dump_path() {
if (NULL == emergency_dump_path) { if (NULL == emergency_dump_path) {
return NULL; return NULL;
} }
strncpy(emergency_dump_path, buffer, emergency_filename_length); strncpy(emergency_dump_path, buffer, emergency_filename_length + 1);
emergency_dump_path[emergency_filename_length] = '\0';
} }
return emergency_dump_path; return emergency_dump_path;
} }
...@@ -407,8 +405,7 @@ bool JfrRepository::set_path(const char* path) { ...@@ -407,8 +405,7 @@ bool JfrRepository::set_path(const char* path) {
if (_path == NULL) { if (_path == NULL) {
return false; return false;
} }
strncpy(_path, path, path_len); strncpy(_path, path, path_len + 1);
_path[path_len] = '\0';
return true; return true;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册