Uses of strncpy sometimes trigger gcc warning -Wstringop-truncation. Some have been correct warnings, some have been false positives. It may also be that some uses aren't being warned about but should be, because strncpy can be tricky to use properly. The places where the warnings occur has varied between gcc versions.
Rather than responding to a different set of complaints from different versions of gcc, we should consider adding os::strncpy_s, modelled on the corresponding C11 function, and replacing uses of strncpy with uses of that function. [Later: A possibly better choice is strscpy; see comments.]
gcc metabug for -Wstringop-truncation bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88781
Rather than responding to a different set of complaints from different versions of gcc, we should consider adding os::strncpy_s, modelled on the corresponding C11 function, and replacing uses of strncpy with uses of that function. [Later: A possibly better choice is strscpy; see comments.]
gcc metabug for -Wstringop-truncation bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88781
- relates to
-
JDK-8214777 Avoid some GCC 8.X strncpy() errors in HotSpot
- Resolved
-
JDK-8223186 HotSpot compile warnings from GCC 9
- Resolved
-
JDK-8231600 Avoid GCC 8 strncpy error in jdk.jdwp.agent
- Resolved
-
JDK-8232084 HotSpot build failed with GCC 9.2.1
- Resolved
-
JDK-8214976 Warn about uses of functions replaced for portability
- Resolved
-
JDK-8252051 Make mlvmJvmtiUtils strncpy uses GCC 10.x friendly
- Resolved
(1 relates to)