JDK-8365896 : Remove unnecessary explicit buffer nul-termination after using os::snprintf
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 26
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-08-21
  • Updated: 2025-10-30
  • Resolved: 2025-10-29
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 26
26 b22Fixed
Related Reports
Relates :  
Description
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
Comments
Changeset: 0f34b020 Branch: master Author: Paul Hübner <phubner@openjdk.org> Committer: Coleen Phillimore <coleenp@openjdk.org> Date: 2025-10-29 12:57:06 +0000 URL: https://git.openjdk.org/jdk/commit/0f34b0203ad8e8e9d4a4dcdd9af2bafa60311fec
29-10-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/27920 Date: 2025-10-21 16:05:31 +0000
21-10-2025