RFR (XS): 8218937: Make mlvmJvmtiUtils strncpy uses GCC 8.x friendly

Mikael Vidstedt mikael.vidstedt at oracle.com
Wed Feb 13 23:45:02 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-8218937
Webrev: http://cr.openjdk.java.net/~mikael/webrevs/8218937/webrev.00/open/webrev/ <http://cr.openjdk.java.net/~mikael/webrevs/8218937/webrev.00/open/webrev/>

GCC 8.2 is producing a warning for mlvmJvmtiUtils.cpp: 

In file included from test/hotspot/jtreg/vmTestbase/vm/mlvm/indy/func/jvmti/share/libIndyRedefineClass.cpp:31: 
test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.cpp: In function 'MethodName* getMethodName(jvmtiEnv*, jmethodID)': 
test/hotspot/jtreg/vmTestbase/vm/mlvm/share/mlvmJvmtiUtils.cpp:80:12: error: 'char* strncpy(char*, const char*, size_t)' specified bound 256 equals destination size [-Werror=stringop-truncation] 
     strncpy(mn->methodName, szName, sizeof(mn->methodName)); 
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Basically, gcc is pointing out that the resulting string is not necessarily going to be terminated. Explicitly checking the length of the source strings provides the information needed to guarantee that the strings will be terminated, and silences the warning.

Passes tier1.

Cheers,
Mikael

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20190213/78f8f40c/attachment.html>


More information about the hotspot-compiler-dev mailing list