Skip to content

Commit

Permalink
8307850: update for deprecated sprintf for jdk.jdi
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken
Backport-of: cbecf422dfef1b53f3a159d2db63ba028d84f152
  • Loading branch information
gdams committed Jul 8, 2024
1 parent b151753 commit 5e3825a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/jdk.jdi/share/native/libdt_shmem/SharedMemoryTransport.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2023, 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
Expand Down Expand Up @@ -64,9 +64,9 @@ throwShmemException(JNIEnv *env, char *message, jint errorCode)
char buf[255];

if (shmemBase_getlasterror(msg, sizeof(msg)) == SYS_OK) {
sprintf(buf, "%s: %s\n", message, msg);
snprintf(buf, sizeof(buf), "%s: %s\n", message, msg);
} else {
sprintf(buf, "%s, error code = %d", message, errorCode);
snprintf(buf, sizeof(buf), "%s, error code = %d", message, errorCode);
}
throwException(env, "java/io/IOException", buf);
}
Expand Down
24 changes: 12 additions & 12 deletions src/jdk.jdi/share/native/libdt_shmem/shmemBase.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ createWithGeneratedName(char *prefix, char *nameBuffer, CreateFunc func, void *a
strcpy(nameBuffer, prefix);
if (i > 0) {
char buf[10];
sprintf(buf, ".%d", i+1);
snprintf(buf, sizeof(buf), ".%d", i+1);
strcat(nameBuffer, buf);
}
error = func(nameBuffer, arg);
Expand Down Expand Up @@ -433,22 +433,22 @@ createStream(char *name, Stream *stream)
jint error;
char objectName[MAX_IPC_NAME];

sprintf(objectName, "%s.mutex", name);
snprintf(objectName, sizeof(objectName), "%s.mutex", name);
error = createWithGeneratedName(objectName, stream->shared->mutexName,
createMutex, &stream->mutex);
if (error != SYS_OK) {
return error;
}

sprintf(objectName, "%s.hasData", name);
snprintf(objectName, sizeof(objectName), "%s.hasData", name);
error = createWithGeneratedName(objectName, stream->shared->hasDataEventName,
createEvent, &stream->hasData);
if (error != SYS_OK) {
sysIPMutexClose(stream->mutex);
return error;
}

sprintf(objectName, "%s.hasSpace", name);
snprintf(objectName, sizeof(objectName), "%s.hasSpace", name);
error = createWithGeneratedName(objectName, stream->shared->hasSpaceEventName,
createEvent, &stream->hasSpace);
if (error != SYS_OK) {
Expand Down Expand Up @@ -571,7 +571,7 @@ openConnection(SharedMemoryTransport *transport, jlong otherPID,
return SYS_NOMEM;
}

sprintf(connection->name, "%s.%" PRId64, transport->name, sysProcessGetID());
snprintf(connection->name, sizeof(connection->name), "%s.%" PRId64, transport->name, sysProcessGetID());
error = sysSharedMemOpen(connection->name, &connection->sharedMemory,
&connection->shared);
if (error != SYS_OK) {
Expand Down Expand Up @@ -639,7 +639,7 @@ createConnection(SharedMemoryTransport *transport, jlong otherPID,
return SYS_NOMEM;
}

sprintf(connection->name, "%s.%" PRId64, transport->name, otherPID);
snprintf(connection->name, sizeof(connection->name), "%s.%" PRId64, transport->name, otherPID);
error = sysSharedMemCreate(connection->name, sizeof(SharedMemory),
&connection->sharedMemory, &connection->shared);
if (error != SYS_OK) {
Expand Down Expand Up @@ -738,7 +738,7 @@ openTransport(const char *address, SharedMemoryTransport **transportPtr)

if (strlen(address) >= MAX_IPC_PREFIX) {
char buf[128];
sprintf(buf, "Error: address strings longer than %d characters are invalid\n", MAX_IPC_PREFIX);
snprintf(buf, sizeof(buf), "Error: address strings longer than %d characters are invalid\n", MAX_IPC_PREFIX);
setLastErrorMsg(buf);
closeTransport(transport);
return SYS_ERR;
Expand Down Expand Up @@ -802,7 +802,7 @@ createTransport(const char *address, SharedMemoryTransport **transportPtr)
} else {
if (strlen(address) >= MAX_IPC_PREFIX) {
char buf[128];
sprintf(buf, "Error: address strings longer than %d characters are invalid\n", MAX_IPC_PREFIX);
snprintf(buf, sizeof(buf), "Error: address strings longer than %d characters are invalid\n", MAX_IPC_PREFIX);
setLastErrorMsg(buf);
closeTransport(transport);
return SYS_ERR;
Expand All @@ -820,23 +820,23 @@ createTransport(const char *address, SharedMemoryTransport **transportPtr)
memset(transport->shared, 0, sizeof(SharedListener));
transport->shared->acceptingPID = sysProcessGetID();

sprintf(objectName, "%s.mutex", transport->name);
snprintf(objectName, sizeof(objectName), "%s.mutex", transport->name);
error = createWithGeneratedName(objectName, transport->shared->mutexName,
createMutex, &transport->mutex);
if (error != SYS_OK) {
closeTransport(transport);
return error;
}

sprintf(objectName, "%s.accept", transport->name);
snprintf(objectName, sizeof(objectName), "%s.accept", transport->name);
error = createWithGeneratedName(objectName, transport->shared->acceptEventName,
createEvent, &transport->acceptEvent);
if (error != SYS_OK) {
closeTransport(transport);
return error;
}

sprintf(objectName, "%s.attach", transport->name);
snprintf(objectName, sizeof(objectName), "%s.attach", transport->name);
error = createWithGeneratedName(objectName, transport->shared->attachEventName,
createEvent, &transport->attachEvent);
if (error != SYS_OK) {
Expand Down Expand Up @@ -1263,7 +1263,7 @@ exitTransportWithError(char *message, char *fileName,
jint error;
char buffer[500];

sprintf(buffer, "Shared Memory Transport \"%s\" (%s), line %d: %s\n",
snprintf(buffer, sizeof(buffer), "Shared Memory Transport \"%s\" (%s), line %d: %s\n",
fileName, date, lineNumber, message);
error = (*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_2);
if (error != JNI_OK) {
Expand Down

1 comment on commit 5e3825a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.