Historically snprintf did not guarantee nul-termination in case of truncation so we have code like:
snprintf(buf, sizeof(buf), "%s", name);
buf[sizeof(buf) - 1] = '\0';
but this explicit nul-termination is no longer necessary.
Additionally we have code that unnecessarily reserves space for an extra nul-terminator e.g [1].
if (ebuf != nullptr && ebuflen > 0) {
os::snprintf_checked(ebuf, ebuflen - 1, "%s", error_report);
}
These should also be cleaned up.
[1] https://github.com/openjdk/jdk/blob/38003a227a55dbd6adb89dcb10dc619f08bb0187/src/hotspot/os/bsd/os_bsd.cpp#L2493
snprintf(buf, sizeof(buf), "%s", name);
buf[sizeof(buf) - 1] = '\0';
but this explicit nul-termination is no longer necessary.
Additionally we have code that unnecessarily reserves space for an extra nul-terminator e.g [1].
if (ebuf != nullptr && ebuflen > 0) {
os::snprintf_checked(ebuf, ebuflen - 1, "%s", error_report);
}
These should also be cleaned up.
[1] https://github.com/openjdk/jdk/blob/38003a227a55dbd6adb89dcb10dc619f08bb0187/src/hotspot/os/bsd/os_bsd.cpp#L2493
- relates to
-
JDK-8347707 Standardise the use of os::snprintf and os::snprintf_checked
-
- Resolved
-