JDK-8214707 : Prevent GCC 8 from reporting error in ClassLoader::file_name_for_class_name()
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 12
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-12-03
  • Updated: 2019-08-15
  • Resolved: 2018-12-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 12 JDK 13
12Fixed 13Fixed
Related Reports
Relates :  
Description
src/hotspot/share/classfile/classLoader.cpp: In static member function ‘static const char* ClassLoader::file_name_for_class_name(const char*, int)’:
src/hotspot/share/classfile/classLoader.cpp:1233:53: error: argument to ‘sizeof’ in ‘char* strncpy(char*, const char*, size_t)’ call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
   strncpy(&file_name[class_name_len], class_suffix, sizeof(class_suffix));
                                                     ^~~~~~~~~~~~~~~~~~~~

The code itself looks correct and it seems having variable for suffix length should be enough.
Comments
http://cr.openjdk.java.net/~dchuyko/8214707/webrev.00/ fine on GCC v8.2
06-12-2018

Just capturing the value of "sizeof(class_suffix)" directly in a variable might not be enough. Suggest computing "file_name_len = class_name_len + sizeof(class_suffix)" and using that as the allocation size, and changing the offending size argument to "file_name_len - class_name_len" (which is == sizeof(class_suffix)). That seems likely to silence the warning.
06-12-2018