RFR(XS): 8218935: Make jfr strncpy uses GCC 8.x friendly

Mikael Vidstedt mikael.vidstedt at oracle.com
Wed Feb 13 22:53:30 UTC 2019


Please review this small fix which updates some uses of strncpy to address some GCC 8.x warnings.

Bug: https://bugs.openjdk.java.net/browse/JDK-8218935
Webrev: http://cr.openjdk.java.net/~mikael/webrevs/8218935/webrev.00/open/webrev/ <http://cr.openjdk.java.net/~mikael/webrevs/8218935/webrev.00/open/webrev/>


Specifically, GCC 8.2 is producing warnings like this:

In function 'char* copy_path(const char*)',
    inlined from 'void JfrChunkState::set_path(const char*)' at src/hotspot/share/jfr/recorder/repository/jfrChunkState.cpp:115:22:
src/hotspot/share/jfr/recorder/repository/jfrChunkState.cpp:103:10: error: 'char* strncpy(char*, const char*, size_t)' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
   strncpy(new_path, path, path_len);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

Basically, gcc is pointing out that the resulting string is not going to be terminated. This is fine from a functional perspective, because in all cases the very next thing we do is add the necessary nul termination, but having strncpy produce a nul terminated string has the benefit of not having to terminate it explicitly, and, of course, silence the warnings.

(Note: additional changes are needed to make the build GCC 8.2 warning free.)

Passes tier1.

Cheers,
Mikael



More information about the hotspot-jfr-dev mailing list