JDK-8214776 : Avoid GCC 8.X strncpy() errors in JFR code
  • Type: Bug
  • Component: hotspot
  • Sub-Component: jfr
  • Affected Version: 12
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2018-12-04
  • Updated: 2019-08-15
  • Resolved: 2019-01-15
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 13
13Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
Gcc 8 has strict (and sometimes buggy) tests for strncpy() misuse.

A common pattern in the JDK is:

   const size_t not_impl_len = strlen(not_impl);
   *str = NEW_C_HEAP_ARRAY(char, not_impl_len+1, mtTracing);
   strncpy(*str, not_impl, not_impl_len);
   (*str)[not_impl_len] = '\0';

More efficient code that does not cause GCC warnings would use strncpy() to add the trailing null, resulting in shorter code:

   strncpy(*str, not_impl, not_impl_len);
   (*str)[not_impl_len] = '\0';

becomes:

   strncpy(*str, not_impl, not_impl_len+1);

(found by compiling with GCC 8.1)
Comments
I've created a separate issue (#8216578) to remove the obsolete function.
11-01-2019

Assigning to Simon as he's Author now.
11-01-2019

[~mikael] Thanks Mikael for pointing this out. It is a remnant from older times and can indeed be removed.
10-01-2019

[~sgehwolf] [~egahlin] [~mgronlun] I wasn't subscribed to the mailing list when the review happened so can't easily comment there, but question: AFAICT JfrOSInterface::JfrOSInterfaceImpl::functionality_not_implemented is dead code? Can the method be be removed?
10-01-2019

Alright then. I'll hold off on pushing this in that case.
12-12-2018

This is subject to the same discussion/debate as for JDK-8214777 where the position seems to be swinging to disabling the warnings until we use a non-buggy gcc.
12-12-2018

@Mikhailo A fix for this has been proposed for review and is about to get pushed[1]. Is there a good reason why this can't be fixed for JDK 12 and pushed today? [1] http://mail.openjdk.java.net/pipermail/hotspot-jfr-dev/2018-December/000288.html
12-12-2018

Runtime Triage team: re-targeting this to JDK 13; the plan is to upgrade GCC to 8.x in JDK 13.
11-12-2018

Assigned this to myself on behalf of Simon Tooke.
04-12-2018