8336289: Obliterate most references to _snprintf in the Windows JDK

Reviewed-by: kbarrett, dholmes, jpai, mullan, djelinski, prr
This commit is contained in:
Julian Waters 2024-08-27 04:13:54 +00:00
parent 78f53efcd6
commit cd9e241f0e
12 changed files with 54 additions and 70 deletions

View File

@ -318,7 +318,7 @@ void Win32AttachOperation::complete(jint result, bufferedStream* result_stream)
BOOL fSuccess;
char msg[32];
_snprintf(msg, sizeof(msg), "%d\n", result);
os::snprintf(msg, sizeof(msg), "%d\n", result);
msg[sizeof(msg) - 1] = '\0';
fSuccess = write_pipe(hPipe, msg, (int)strlen(msg));

View File

@ -1776,14 +1776,14 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
}
if (lib_arch_str != nullptr) {
::_snprintf(ebuf, ebuflen - 1,
"Can't load %s-bit .dll on a %s-bit platform",
lib_arch_str, running_arch_str);
os::snprintf(ebuf, ebuflen - 1,
"Can't load %s-bit .dll on a %s-bit platform",
lib_arch_str, running_arch_str);
} else {
// don't know what architecture this dll was build for
::_snprintf(ebuf, ebuflen - 1,
"Can't load this .dll (machine code=0x%x) on a %s-bit platform",
lib_arch, running_arch_str);
os::snprintf(ebuf, ebuflen - 1,
"Can't load this .dll (machine code=0x%x) on a %s-bit platform",
lib_arch, running_arch_str);
}
JFR_ONLY(load_event.set_error_msg(ebuf);)
return nullptr;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -165,7 +165,7 @@ static char* get_user_tmp_dir(const char* user) {
char* dirname = NEW_C_HEAP_ARRAY(char, nbytes, mtInternal);
// construct the path name to user specific tmp directory
_snprintf(dirname, nbytes, "%s\\%s_%s", tmpdir, perfdir, user);
os::snprintf(dirname, nbytes, "%s\\%s_%s", tmpdir, perfdir, user);
return dirname;
}
@ -455,7 +455,7 @@ static char *get_sharedmem_objectname(const char* user, int vmid) {
//
nbytes += UINT_CHARS;
char* name = NEW_C_HEAP_ARRAY(char, nbytes, mtInternal);
_snprintf(name, nbytes, "%s_%s_%u", PERFDATA_NAME, user, vmid);
os::snprintf(name, nbytes, "%s_%s_%u", PERFDATA_NAME, user, vmid);
return name;
}
@ -471,7 +471,7 @@ static char* get_sharedmem_filename(const char* dirname, int vmid) {
size_t nbytes = strlen(dirname) + UINT_CHARS + 2;
char* name = NEW_C_HEAP_ARRAY(char, nbytes, mtInternal);
_snprintf(name, nbytes, "%s\\%d", dirname, vmid);
os::snprintf(name, nbytes, "%s\\%d", dirname, vmid);
return name;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -328,7 +328,7 @@ public:
printf("*** cannot allocate memory\n");
doabort();
}
_snprintf(cptr, MAX_PATH, "\"%s\" %s", argv[0], cmdline);
snprintf(cptr, MAX_PATH, "\"%s\" %s", argv[0], cmdline);
JLI_CmdToArgs(cptr);
free(cptr);
StdArg *kargv = JLI_GetStdArgs();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,11 +26,6 @@
#include "splashscreen_impl.h"
#include "splashscreen_gfx_impl.h"
#define BUFF_SIZE 1024
#ifdef _MSC_VER
# ifndef snprintf
# define snprintf _snprintf
# endif
#endif
int splashIsVisible = 0;
Splash *

View File

@ -141,7 +141,7 @@ void AwtDebugSupport::AssertCallback(const char * expr, const char * file, int l
msgBuffer = (LPSTR)"<Could not get GetLastError() message text>";
}
// format the assertion message
_snprintf(assertMsg, ASSERT_MSG_SIZE, AssertFmt, expr, file, line, lastError, msgBuffer);
snprintf(assertMsg, ASSERT_MSG_SIZE, AssertFmt, expr, file, line, lastError, msgBuffer);
if (fret != 0) {
LocalFree(msgBuffer);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1526,8 +1526,8 @@ BOOL UpdateMessageNumber () {
size_t messageNumber = g_MessageHistory.GetCurrentMessageIndex() + 1;
char text [32] = {0};
if ( 0 != messageCount ) {
::_snprintf(text, sizeof(text), "%d of %d", (int)messageNumber,
(int) messageCount);
::snprintf(text, sizeof(text), "%d of %d", (int)messageNumber,
(int) messageCount);
}
return ::SetWindowText(dlgItem, text);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -39,7 +39,7 @@ void *p11FindFunction(JNIEnv *env, jlong jHandle, const char *functionName) {
void *fAddress = GetProcAddress(hModule, functionName);
if (fAddress == NULL) {
char errorMessage[256];
_snprintf(errorMessage, sizeof(errorMessage), "Symbol not found: %s", functionName);
snprintf(errorMessage, sizeof(errorMessage), "Symbol not found: %s", functionName);
p11ThrowNullPointerException(env, errorMessage);
return NULL;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,12 +33,6 @@
*/
#ifdef _WINDOWS
// Disable CRT security warning against _snprintf
#pragma warning (disable : 4996)
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#include <windows.h>
#include <sys/types.h>
#include <sys/stat.h>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -56,7 +56,7 @@ static void dll_build_name(char* buffer, size_t buflen,
path = strtok_s(paths_copy, PATH_SEPARATOR, &next_token);
while (path != NULL) {
size_t result_len = (size_t)_snprintf(buffer, buflen, "%s\\%s.dll", path, fname);
size_t result_len = (size_t) snprintf(buffer, buflen, "%s\\%s.dll", path, fname);
if (result_len >= buflen) {
EXIT_ERROR(JVMTI_ERROR_INVALID_LOCATION, "One or more of the library paths supplied to jdwp, "
"likely by sun.boot.library.path, is too long.");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,11 +34,6 @@ typedef unsigned long UNSIGNED_JINT;
#define MAXPATHLEN _MAX_PATH
/* Needed on Windows because names seem to be hidden in stdio.h. */
#define snprintf _snprintf
#define vsnprintf _vsnprintf
/* On little endian machines, convert java big endian numbers. */
#define HOST_TO_JAVA_CHAR(x) (((x & 0xff) << 8) | ((x >> 8) & (0xff)))

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -436,13 +436,13 @@ makeFullCounterPath(const char* const objectName,
return NULL;
}
_snprintf(fullCounterPath,
fullCounterPathLen,
PROCESS_OBJECT_INSTANCE_COUNTER_FMT,
objectName,
imageName,
instance,
counterName);
snprintf(fullCounterPath,
fullCounterPathLen,
PROCESS_OBJECT_INSTANCE_COUNTER_FMT,
objectName,
imageName,
instance,
counterName);
} else {
if (instance) {
/*
@ -472,18 +472,18 @@ makeFullCounterPath(const char* const objectName,
}
if (instance) {
_snprintf(fullCounterPath,
fullCounterPathLen,
OBJECT_WITH_INSTANCES_COUNTER_FMT,
objectName,
instance,
counterName);
snprintf(fullCounterPath,
fullCounterPathLen,
OBJECT_WITH_INSTANCES_COUNTER_FMT,
objectName,
instance,
counterName);
} else {
_snprintf(fullCounterPath,
fullCounterPathLen,
OBJECT_COUNTER_FMT,
objectName,
counterName);
snprintf(fullCounterPath,
fullCounterPathLen,
OBJECT_COUNTER_FMT,
objectName,
counterName);
}
}
@ -719,10 +719,10 @@ currentQueryIndexForProcess(void) {
PDH_FMT_COUNTERVALUE counterValue;
PDH_STATUS res;
_snprintf(fullIDProcessCounterPath,
MAX_PATH,
pdhIDProcessCounterFmt,
index);
snprintf(fullIDProcessCounterPath,
MAX_PATH,
pdhIDProcessCounterFmt,
index);
if (addCounter(tmpQuery, fullIDProcessCounterPath, &handleCounter) != 0) {
break;
@ -1059,13 +1059,13 @@ allocateAndInitializePdhConstants() {
}
/* "\Process(java#%d)\ID Process" */
_snprintf(pdhIDProcessCounterFmt,
pdhIDProcessCounterFmtLen,
PROCESS_OBJECT_INSTANCE_COUNTER_FMT,
pdhLocalizedProcessObject,
pdhProcessImageName,
"%d",
pdhLocalizedIDProcessCounter);
snprintf(pdhIDProcessCounterFmt,
pdhIDProcessCounterFmtLen,
PROCESS_OBJECT_INSTANCE_COUNTER_FMT,
pdhLocalizedProcessObject,
pdhProcessImageName,
"%d",
pdhLocalizedIDProcessCounter);
pdhIDProcessCounterFmt[pdhIDProcessCounterFmtLen] = '\0';