Skip to content

Commit f019a81

Browse files
committed
8303830: update for deprecated sprintf for jdk.accessibility
Backport-of: 44fa12e7511a0b08999c1f1fb7da33bc6578b183
1 parent ef24cdf commit f019a81

File tree

7 files changed

+42
-42
lines changed

7 files changed

+42
-42
lines changed

src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -125,7 +125,7 @@ char *printError(char *msg) {
125125
va_list argprt;
126126

127127
va_start(argprt, msg); // set up argptr
128-
vsprintf(buf, msg, argprt);
128+
vsnprintf(buf, sizeof(buf), msg, argprt);
129129
#ifdef SEND_TO_OUTPUT_DEBUG_STRING
130130
OutputDebugString(buf);
131131
#endif
@@ -153,7 +153,7 @@ char *printError(char *msg) {
153153
va_list argprt;
154154

155155
va_start(argprt, msg); // set up argptr
156-
vsprintf(buf, msg, argprt);
156+
vsnprintf(buf, sizeof(buf), msg, argprt);
157157
#ifdef SEND_TO_OUTPUT_DEBUG_STRING
158158
OutputDebugString(buf);
159159
#endif
@@ -181,8 +181,8 @@ char *printError(char *msg) {
181181
va_list argprt;
182182

183183
va_start(argprt, msg); // set up argptr
184-
sprintf(charmsg, "%ls", msg); // convert format string to multi-byte
185-
vsprintf(buf, charmsg, argprt);
184+
snprintf(charmsg, sizeof(charmsg), "%ls", msg); // convert format string to multi-byte
185+
vsnprintf(buf, sizeof(buf), charmsg, argprt);
186186
#ifdef SEND_TO_OUTPUT_DEBUG_STRING
187187
OutputDebugString(buf);
188188
#endif
@@ -211,8 +211,8 @@ char *printError(char *msg) {
211211
va_list argprt;
212212

213213
va_start(argprt, msg); // set up argptr
214-
sprintf(charmsg, "%ls", msg); // convert format string to multi-byte
215-
vsprintf(buf, charmsg, argprt);
214+
snprintf(charmsg, sizeof(charmsg), "%ls", msg); // convert format string to multi-byte
215+
vsnprintf(buf, sizeof(buf), charmsg, argprt);
216216
#ifdef SEND_TO_OUTPUT_DEBUG_STRING
217217
OutputDebugString(buf);
218218
#endif

src/jdk.accessibility/windows/native/jaccessinspector/jaccessinspector.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -609,7 +609,7 @@ void HandlePropertyChildChange( long vmID, PropertyChangeEvent event,
609609
char buffer[HUGE_BUFSIZE];
610610
char *bufOffset;
611611

612-
sprintf( buffer,
612+
snprintf( buffer, sizeof(buffer),
613613
"Child property changed event:\r\n=======================\r\n\r\n" );
614614

615615
if (oldChild != 0) {
@@ -647,7 +647,7 @@ void HandlePropertyActiveDescendentChange( long vmID, PropertyChangeEvent event,
647647
JOBJECT64 newActiveDescendent ) {
648648
char buffer[HUGE_BUFSIZE];
649649

650-
sprintf( buffer,
650+
snprintf( buffer, sizeof(buffer),
651651
"ActiveDescendent property changed event:\r\n=======================\r\n\r\n" );
652652

653653
#ifdef _notdef

src/jdk.accessibility/windows/native/jaccesswalker/jaccesswalker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -542,7 +542,7 @@ void Jaccesswalker::addComponentNodes(long vmID, AccessibleContext context,
542542
}
543543
} else {
544544
char s[LINE_BUFSIZE];
545-
sprintf( s,
545+
snprintf( s, sizeof(s),
546546
"ERROR calling GetAccessibleContextInfo; vmID = %X, context = %p",
547547
vmID, (void*)context );
548548

src/jdk.accessibility/windows/native/libwindowsaccessbridge/AccessBridgeEventHandler.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -161,9 +161,9 @@ AccessBridgeEventHandler::firePropertyChange(long vmID,
161161
wchar_t *newName) {
162162
DEBUG_CODE(char debugBuf[255]);
163163
#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)
164-
DEBUG_CODE(sprintf(debugBuf, "\r\nCalling firePropertyChange(%p, %p):\r\n", event, source));
164+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), "\r\nCalling firePropertyChange(%p, %p):\r\n", event, source));
165165
#else // JOBJECT64 is jlong (64 bit)
166-
DEBUG_CODE(sprintf(debugBuf, "\r\nCalling firePropertyChange(%016I64X, %016I64X):\r\n", event, source));
166+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), "\r\nCalling firePropertyChange(%016I64X, %016I64X):\r\n", event, source));
167167
#endif
168168
DEBUG_CODE(AppendToCallInfo(debugBuf));
169169

@@ -194,7 +194,7 @@ const char fireEventDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s(%01
194194
#define FIRE_EVENT(method, FPprototype, eventFP) \
195195
void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source) { \
196196
DEBUG_CODE(char debugBuf[255]); \
197-
DEBUG_CODE(sprintf(debugBuf, fireEventDebugString, #method, event, source, vmID)); \
197+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), fireEventDebugString, #method, event, source, vmID)); \
198198
DEBUG_CODE(AppendToCallInfo(debugBuf)); \
199199
if (eventFP != (FPprototype) 0) { \
200200
eventFP(vmID, event, source); \
@@ -205,7 +205,7 @@ const char fireEventDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s(%01
205205

206206
void AccessBridgeEventHandler::fireJavaShutdown(long vmID) {
207207
DEBUG_CODE(char debugBuf[255]);
208-
DEBUG_CODE(sprintf(debugBuf, "[INFO]: Calling fireJavaShutdown; vmID = %X\r\n", vmID));
208+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), "[INFO]: Calling fireJavaShutdown; vmID = %X\r\n", vmID));
209209
DEBUG_CODE(AppendToCallInfo(debugBuf));
210210
if (javaShutdownFP != (AccessBridge_JavaShutdownFP) 0) {
211211
javaShutdownFP(vmID);
@@ -249,7 +249,7 @@ const char firePropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandle
249249
#define FIRE_PROPERTY_CHANGE(method, FPprototype, eventFP) \
250250
void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source) { \
251251
DEBUG_CODE(char debugBuf[255]); \
252-
DEBUG_CODE(sprintf(debugBuf, firePropertyChangeDebugString, #method, event, source)); \
252+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), firePropertyChangeDebugString, #method, event, source)); \
253253
DEBUG_CODE(AppendToCallInfo(debugBuf)); \
254254
if (eventFP != (FPprototype) 0) { \
255255
eventFP(vmID, event, source); \
@@ -278,7 +278,7 @@ const char fireStringPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEvent
278278
void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source, \
279279
wchar_t *oldValue, wchar_t *newValue) { \
280280
DEBUG_CODE(char debugBuf[255]); \
281-
DEBUG_CODE(sprintf(debugBuf, fireStringPropertyChangeDebugString, #method, event, source, oldValue, newValue)); \
281+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), fireStringPropertyChangeDebugString, #method, event, source, oldValue, newValue)); \
282282
DEBUG_CODE(AppendToCallInfo(debugBuf)); \
283283
if (eventFP != (FPprototype) 0) { \
284284
eventFP(vmID, event, source, oldValue, newValue); \
@@ -307,7 +307,7 @@ const char fireIntPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHan
307307
void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source, \
308308
int oldValue, int newValue) { \
309309
DEBUG_CODE(char debugBuf[255]); \
310-
DEBUG_CODE(sprintf(debugBuf, fireIntPropertyChangeDebugString, #method, event, source, oldValue, newValue)); \
310+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), fireIntPropertyChangeDebugString, #method, event, source, oldValue, newValue)); \
311311
DEBUG_CODE(AppendToCallInfo(debugBuf)); \
312312
if (eventFP != (FPprototype) 0) { \
313313
eventFP(vmID, event, source, oldValue, newValue); \
@@ -336,7 +336,7 @@ const char fireACPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHand
336336
void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source, \
337337
JOBJECT64 oldValue, JOBJECT64 newValue) { \
338338
DEBUG_CODE(char debugBuf[255]); \
339-
DEBUG_CODE(sprintf(debugBuf, fireACPropertyChangeDebugString, #method, event, source, oldValue, newValue)); \
339+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), fireACPropertyChangeDebugString, #method, event, source, oldValue, newValue)); \
340340
DEBUG_CODE(AppendToCallInfo(debugBuf)); \
341341
if (eventFP != (FPprototype) 0) { \
342342
eventFP(vmID, event, source, oldValue, newValue); \

src/jdk.accessibility/windows/native/libwindowsaccessbridge/AccessBridgeJavaVMInstance.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -68,7 +68,7 @@ AccessBridgeJavaVMInstance::AccessBridgeJavaVMInstance(HWND ourABWindow,
6868
nextJVMInstance = next;
6969
memoryMappedFileMapHandle = (HANDLE) 0;
7070
memoryMappedView = (char *) 0;
71-
sprintf(memoryMappedFileName, "AccessBridge-%p-%p.mmf",
71+
snprintf(memoryMappedFileName, sizeof(memoryMappedFileName), "AccessBridge-%p-%p.mmf",
7272
ourAccessBridgeWindow, javaAccessBridgeWindow);
7373
}
7474

@@ -85,14 +85,14 @@ AccessBridgeJavaVMInstance::~AccessBridgeJavaVMInstance() {
8585
// if IPC memory mapped file view is valid, unmap it
8686
goingAway = TRUE;
8787
if (memoryMappedView != (char *) 0) {
88-
DEBUG_CODE(sprintf(buffer, " unmapping memoryMappedView; view = %p\r\n", memoryMappedView));
88+
DEBUG_CODE(snprintf(buffer, sizeof(buffer), " unmapping memoryMappedView; view = %p\r\n", memoryMappedView));
8989
DEBUG_CODE(AppendToCallInfo(buffer));
9090
UnmapViewOfFile(memoryMappedView);
9191
memoryMappedView = (char *) 0;
9292
}
9393
// if IPC memory mapped file handle map is open, close it
9494
if (memoryMappedFileMapHandle != (HANDLE) 0) {
95-
DEBUG_CODE(sprintf(buffer, " closing memoryMappedFileMapHandle; handle = %p\r\n", memoryMappedFileMapHandle));
95+
DEBUG_CODE(snprintf(buffer, sizeof(buffer), " closing memoryMappedFileMapHandle; handle = %p\r\n", memoryMappedFileMapHandle));
9696
DEBUG_CODE(AppendToCallInfo(buffer));
9797
CloseHandle(memoryMappedFileMapHandle);
9898
memoryMappedFileMapHandle = (HANDLE) 0;
@@ -131,11 +131,11 @@ AccessBridgeJavaVMInstance::initiateIPC() {
131131
memoryMappedFileName);
132132
if (memoryMappedFileMapHandle == NULL) {
133133
errorCode = GetLastError();
134-
DEBUG_CODE(sprintf(debugBuf, " Failed to CreateFileMapping for %s, error: %X", memoryMappedFileName, errorCode));
134+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), " Failed to CreateFileMapping for %s, error: %X", memoryMappedFileName, errorCode));
135135
DEBUG_CODE(AppendToCallInfo(debugBuf));
136136
return errorCode;
137137
} else {
138-
DEBUG_CODE(sprintf(debugBuf, " CreateFileMapping worked - filename: %s\r\n", memoryMappedFileName));
138+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), " CreateFileMapping worked - filename: %s\r\n", memoryMappedFileName));
139139
DEBUG_CODE(AppendToCallInfo(debugBuf));
140140
}
141141

@@ -144,11 +144,11 @@ AccessBridgeJavaVMInstance::initiateIPC() {
144144
0, 0, 0);
145145
if (memoryMappedView == NULL) {
146146
errorCode = GetLastError();
147-
DEBUG_CODE(sprintf(debugBuf, " Failed to MapViewOfFile for %s, error: %X", memoryMappedFileName, errorCode));
147+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), " Failed to MapViewOfFile for %s, error: %X", memoryMappedFileName, errorCode));
148148
DEBUG_CODE(AppendToCallInfo(debugBuf));
149149
return errorCode;
150150
} else {
151-
DEBUG_CODE(sprintf(debugBuf, " MapViewOfFile worked - view: %p\r\n", memoryMappedView));
151+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), " MapViewOfFile worked - view: %p\r\n", memoryMappedView));
152152
DEBUG_CODE(AppendToCallInfo(debugBuf));
153153
}
154154

@@ -169,12 +169,12 @@ AccessBridgeJavaVMInstance::initiateIPC() {
169169

170170
// look for the JavaDLL's answer to see if it could read the file
171171
if (strcmp(memoryMappedView, AB_MEMORY_MAPPED_FILE_OK_ANSWER) != 0) {
172-
DEBUG_CODE(sprintf(debugBuf, " JavaVM failed to deal with memory mapped file %s\r\n",
172+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), " JavaVM failed to deal with memory mapped file %s\r\n",
173173
memoryMappedFileName));
174174
DEBUG_CODE(AppendToCallInfo(debugBuf));
175175
return -1;
176176
} else {
177-
DEBUG_CODE(sprintf(debugBuf, " Success! JavaVM accpeted our file\r\n"));
177+
DEBUG_CODE(snprintf(debugBuf, sizeof(debugBuf), " Success! JavaVM accpeted our file\r\n"));
178178
DEBUG_CODE(AppendToCallInfo(debugBuf));
179179
}
180180

@@ -245,16 +245,16 @@ AccessBridgeJavaVMInstance::sendMemoryPackage(char *buffer, long bufsize) {
245245
BOOL retval = FALSE;
246246

247247
DEBUG_CODE(char outputBuf[256]);
248-
DEBUG_CODE(sprintf(outputBuf, "AccessBridgeJavaVMInstance::sendMemoryPackage(, %d)", bufsize));
248+
DEBUG_CODE(snprintf(outputBuf, sizeof(outputBuf), "AccessBridgeJavaVMInstance::sendMemoryPackage(, %d)", bufsize));
249249
DEBUG_CODE(AppendToCallInfo(outputBuf));
250250

251251
DEBUG_CODE(PackageType *type = (PackageType *) buffer);
252252
DEBUG_CODE(if (*type == cGetAccessibleTextRangePackage) {)
253253
DEBUG_CODE(AppendToCallInfo(" 'buffer' contains:"));
254254
DEBUG_CODE(GetAccessibleTextRangePackage *pkg = (GetAccessibleTextRangePackage *) (buffer + sizeof(PackageType)));
255-
DEBUG_CODE(sprintf(outputBuf, " PackageType = %X", *type));
255+
DEBUG_CODE(snprintf(outputBuf, sizeof(outputBuf), " PackageType = %X", *type));
256256
DEBUG_CODE(AppendToCallInfo(outputBuf));
257-
DEBUG_CODE(sprintf(outputBuf, " GetAccessibleTextRange: start = %d, end = %d, rText = %ls",
257+
DEBUG_CODE(snprintf(outputBuf, sizeof(outputBuf), " GetAccessibleTextRange: start = %d, end = %d, rText = %ls",
258258
pkg->start, pkg->end, pkg->rText));
259259
DEBUG_CODE(AppendToCallInfo(outputBuf));
260260
DEBUG_CODE(})
@@ -269,7 +269,7 @@ AccessBridgeJavaVMInstance::sendMemoryPackage(char *buffer, long bufsize) {
269269
DEBUG_CODE(if (*type == cGetAccessibleTextItemsPackage) {)
270270
DEBUG_CODE(AppendToCallInfo(" 'memoryMappedView' now contains:"));
271271
DEBUG_CODE(GetAccessibleTextItemsPackage *pkg = (GetAccessibleTextItemsPackage *) (buffer + sizeof(PackageType)));
272-
DEBUG_CODE(sprintf(outputBuf, " PackageType = %X", *type));
272+
DEBUG_CODE(snprintf(outputBuf, sizeof(outputBuf), " PackageType = %X", *type));
273273
DEBUG_CODE(AppendToCallInfo(outputBuf));
274274
DEBUG_CODE(})
275275
}

src/jdk.accessibility/windows/native/libwindowsaccessbridge/WinAccessBridge.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -160,7 +160,7 @@ extern "C" {
160160
*/
161161

162162
char buf[1024];
163-
sprintf(buf, "WinAccessBridge: %s", s);
163+
snprintf(buf, sizeof(buf), "WinAccessBridge: %s", s);
164164
OutputDebugString(buf);
165165
}
166166

src/jdk.accessibility/windows/native/toolscommon/AccessInfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,7 +49,7 @@ char *getTimeAndDate() {
4949
if( newtime->tm_hour == 0 ) /*Set hour to 12 if midnight. */
5050
newtime->tm_hour = 12;
5151

52-
sprintf(datebuf, "%.19s %s\n", asctime( newtime ), am_pm );
52+
snprintf(datebuf, sizeof(datebuf), "%.19s %s\n", asctime( newtime ), am_pm );
5353
return (char *)datebuf;
5454
}
5555

@@ -67,7 +67,7 @@ void displayAndLog(HWND hDlg, int nIDDlgItem, FILE *logfile, char *msg, ...) {
6767
va_list argprt;
6868

6969
va_start(argprt, msg);
70-
vsprintf(tmpbuf, msg, argprt);
70+
vsnprintf(tmpbuf, sizeof(tmpbuf), msg, argprt);
7171

7272
SetDlgItemText(hDlg, nIDDlgItem, tmpbuf);
7373

@@ -95,7 +95,7 @@ void logString(FILE *logfile, char *msg, ...) {
9595
va_list argprt;
9696

9797
va_start(argprt, msg);
98-
vsprintf(tmpbuf, msg, argprt);
98+
vsnprintf(tmpbuf, sizeof(tmpbuf), msg, argprt);
9999

100100
fprintf(logfile, tmpbuf);
101101
fprintf(logfile, "\n");
@@ -119,7 +119,7 @@ BOOL appendToBuffer(char *buf, size_t buflen, char *msg, ...) {
119119
va_list argprt;
120120

121121
va_start(argprt, msg);
122-
vsprintf(tmpbuf, msg, argprt);
122+
vsnprintf(tmpbuf, sizeof(tmpbuf), msg, argprt);
123123

124124
// verify there's enough space in the buffer
125125
size_t spaceRemaining = buflen - strlen(buf) - 1;

0 commit comments

Comments
 (0)