Skip to content

Commit a3a7273

Browse files
author
duke
committedMay 28, 2024
Automatic merge of jdk:master into master
2 parents 4e9061c + 673f767 commit a3a7273

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed
 

‎src/hotspot/os/posix/os_posix.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,6 @@ char* os::map_memory_to_file_aligned(size_t size, size_t alignment, int file_des
425425
return aligned_base;
426426
}
427427

428-
int os::vsnprintf(char* buf, size_t len, const char* fmt, va_list args) {
429-
// All supported POSIX platforms provide C99 semantics.
430-
ALLOW_C_FUNCTION(::vsnprintf, int result = ::vsnprintf(buf, len, fmt, args);)
431-
// If an encoding error occurred (result < 0) then it's not clear
432-
// whether the buffer is NUL terminated, so ensure it is.
433-
if ((result < 0) && (len > 0)) {
434-
buf[len - 1] = '\0';
435-
}
436-
return result;
437-
}
438-
439428
int os::get_fileno(FILE* fp) {
440429
return NOT_AIX(::)fileno(fp);
441430
}

‎src/hotspot/os/windows/os_windows.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -1739,17 +1739,6 @@ void os::get_summary_os_info(char* buf, size_t buflen) {
17391739
if (nl != nullptr) *nl = '\0';
17401740
}
17411741

1742-
int os::vsnprintf(char* buf, size_t len, const char* fmt, va_list args) {
1743-
// Starting with Visual Studio 2015, vsnprint is C99 compliant.
1744-
ALLOW_C_FUNCTION(::vsnprintf, int result = ::vsnprintf(buf, len, fmt, args);)
1745-
// If an encoding error occurred (result < 0) then it's not clear
1746-
// whether the buffer is NUL terminated, so ensure it is.
1747-
if ((result < 0) && (len > 0)) {
1748-
buf[len - 1] = '\0';
1749-
}
1750-
return result;
1751-
}
1752-
17531742
static inline time_t get_mtime(const char* filename) {
17541743
struct stat st;
17551744
int ret = os::stat(filename, &st);

‎src/hotspot/share/runtime/os.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ int os::snprintf_checked(char* buf, size_t len, const char* fmt, ...) {
111111
return result;
112112
}
113113

114+
int os::vsnprintf(char* buf, size_t len, const char* fmt, va_list args) {
115+
ALLOW_C_FUNCTION(::vsnprintf, int result = ::vsnprintf(buf, len, fmt, args);)
116+
// If an encoding error occurred (result < 0) then it's not clear
117+
// whether the buffer is NUL terminated, so ensure it is.
118+
if ((result < 0) && (len > 0)) {
119+
buf[len - 1] = '\0';
120+
}
121+
return result;
122+
}
123+
114124
// Fill in buffer with current local time as an ISO-8601 string.
115125
// E.g., YYYY-MM-DDThh:mm:ss.mmm+zzzz.
116126
// Returns buffer, or null if it failed.

‎src/hotspot/share/runtime/os.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,8 @@ class os: AllStatic {
771771
static void *find_agent_function(JvmtiAgent *agent_lib, bool check_lib,
772772
const char *syms[], size_t syms_len);
773773

774-
// Provide C99 compliant versions of these functions, since some versions
775-
// of some platforms don't.
774+
// Provide wrapper versions of these functions to guarantee NUL-termination
775+
// in all cases.
776776
static int vsnprintf(char* buf, size_t len, const char* fmt, va_list args) ATTRIBUTE_PRINTF(3, 0);
777777
static int snprintf(char* buf, size_t len, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);
778778

0 commit comments

Comments
 (0)
Failed to load comments.