mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
Add os::vsnprintf and os::snprintf. Reviewed-by: lfoltan, stuefe, mlarsson
This commit is contained in:
parent
f2c21c058d
commit
d2ce0ae7d4
12 changed files with 193 additions and 50 deletions
|
@ -2670,23 +2670,19 @@ extern "C" {
|
|||
|
||||
ATTRIBUTE_PRINTF(3, 0)
|
||||
int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
|
||||
// see bug 4399518, 4417214
|
||||
// Reject count values that are negative signed values converted to
|
||||
// unsigned; see bug 4399518, 4417214
|
||||
if ((intptr_t)count <= 0) return -1;
|
||||
|
||||
int result = vsnprintf(str, count, fmt, args);
|
||||
// Note: on truncation vsnprintf(3) on Unix returns numbers of
|
||||
// characters which would have been written had the buffer been large
|
||||
// enough; on Windows, it returns -1. We handle both cases here and
|
||||
// always return -1, and perform null termination.
|
||||
if ((result > 0 && (size_t)result >= count) || result == -1) {
|
||||
str[count - 1] = '\0';
|
||||
int result = os::vsnprintf(str, count, fmt, args);
|
||||
if (result > 0 && (size_t)result >= count) {
|
||||
result = -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ATTRIBUTE_PRINTF(3, 0)
|
||||
ATTRIBUTE_PRINTF(3, 4)
|
||||
int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
|
||||
va_list args;
|
||||
int len;
|
||||
|
@ -2696,7 +2692,7 @@ int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
|
|||
return len;
|
||||
}
|
||||
|
||||
ATTRIBUTE_PRINTF(2,3)
|
||||
ATTRIBUTE_PRINTF(2, 3)
|
||||
int jio_fprintf(FILE* f, const char *fmt, ...) {
|
||||
int len;
|
||||
va_list args;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue