Details
-
Bug
-
Resolution: Duplicate
-
P4
-
12
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)
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)
Attachments
Issue Links
- duplicates
-
JDK-8216578 Remove unused/obsolete method in JFR code
- Resolved
- relates to
-
JDK-8214777 Avoid some GCC 8.X strncpy() errors in HotSpot
- Resolved
-
JDK-8213153 Clean up GCC 8 errors
- Closed