8218935: Make jfr strncpy uses GCC 8.x friendly

Thu, 14 Feb 2019 15:17:03 -0800

author
mikael
date
Thu, 14 Feb 2019 15:17:03 -0800
changeset 9880
3549c2f110d2
parent 9879
d2b51a10084d
child 9881
8a0aca5caca0

8218935: Make jfr strncpy uses GCC 8.x friendly
Reviewed-by: clanger

src/share/vm/jfr/recorder/checkpoint/types/jfrThreadGroup.cpp file | annotate | diff | comparison | revisions
src/share/vm/jfr/recorder/repository/jfrChunkState.cpp file | annotate | diff | comparison | revisions
src/share/vm/jfr/recorder/repository/jfrRepository.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/jfr/recorder/checkpoint/types/jfrThreadGroup.cpp	Tue Jan 15 21:17:35 2019 +0100
     1.2 +++ b/src/share/vm/jfr/recorder/checkpoint/types/jfrThreadGroup.cpp	Thu Feb 14 15:17:03 2019 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -238,9 +238,8 @@
    1.11    assert(_thread_group_name == NULL, "invariant");
    1.12    if (tgname != NULL) {
    1.13      size_t len = strlen(tgname);
    1.14 -    _thread_group_name = JfrCHeapObj::new_array<char>(len+1);
    1.15 -    strncpy(_thread_group_name, tgname, len);
    1.16 -    _thread_group_name[len] = '\0';
    1.17 +    _thread_group_name = JfrCHeapObj::new_array<char>(len + 1);
    1.18 +    strncpy(_thread_group_name, tgname, len + 1);
    1.19    }
    1.20  }
    1.21  
     2.1 --- a/src/share/vm/jfr/recorder/repository/jfrChunkState.cpp	Tue Jan 15 21:17:35 2019 +0100
     2.2 +++ b/src/share/vm/jfr/recorder/repository/jfrChunkState.cpp	Thu Feb 14 15:17:03 2019 -0800
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -99,8 +99,7 @@
    2.11    assert(path != NULL, "invariant");
    2.12    const size_t path_len = strlen(path);
    2.13    char* new_path = JfrCHeapObj::new_array<char>(path_len + 1);
    2.14 -  strncpy(new_path, path, path_len);
    2.15 -  new_path[path_len] = '\0';
    2.16 +  strncpy(new_path, path, path_len + 1);
    2.17    return new_path;
    2.18  }
    2.19  
     3.1 --- a/src/share/vm/jfr/recorder/repository/jfrRepository.cpp	Tue Jan 15 21:17:35 2019 +0100
     3.2 +++ b/src/share/vm/jfr/recorder/repository/jfrRepository.cpp	Thu Feb 14 15:17:03 2019 -0800
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -209,8 +209,7 @@
    3.11    if (entry_name == NULL) {
    3.12      return NULL;
    3.13    }
    3.14 -  strncpy(entry_name, entry, entry_len);
    3.15 -  entry_name[entry_len] = '\0';
    3.16 +  strncpy(entry_name, entry, entry_len + 1);
    3.17    const char* const fully_qualified_path_entry = fully_qualified(entry_name);
    3.18    if (NULL == fully_qualified_path_entry) {
    3.19      return NULL;
    3.20 @@ -332,8 +331,7 @@
    3.21      if (NULL == emergency_dump_path) {
    3.22        return NULL;
    3.23      }
    3.24 -    strncpy(emergency_dump_path, buffer, emergency_filename_length);
    3.25 -    emergency_dump_path[emergency_filename_length] = '\0';
    3.26 +    strncpy(emergency_dump_path, buffer, emergency_filename_length + 1);
    3.27    }
    3.28    return emergency_dump_path;
    3.29  }
    3.30 @@ -407,8 +405,7 @@
    3.31    if (_path == NULL) {
    3.32      return false;
    3.33    }
    3.34 -  strncpy(_path, path, path_len);
    3.35 -  _path[path_len] = '\0';
    3.36 +  strncpy(_path, path, path_len + 1);
    3.37    return true;
    3.38  }
    3.39  

mercurial