Skip to content

Commit 8d974ea

Browse files
committed
8299378: sprintf is deprecated in Xcode 14
Reviewed-by: sgehwolf, andrew Backport-of: 38cfc591725de478879266584280562f0ba4b42f
1 parent e191f94 commit 8d974ea

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

test/hotspot/gtest/logging/test_logDecorators.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "precompiled.hpp"
2525
#include "jvm.h"
2626
#include "logging/logDecorators.hpp"
27+
#include "runtime/os.hpp"
2728
#include "unittest.hpp"
2829

2930
static LogDecorators::Decorator decorator_array[] = {
@@ -173,7 +174,7 @@ TEST(LogDecorators, combine_with) {
173174

174175
// Select first and third decorator for dec1
175176
char input[64];
176-
sprintf(input, "%s,%s", decorator_name_array[0], decorator_name_array[3]);
177+
os::snprintf_checked(input, sizeof(input), "%s,%s", decorator_name_array[0], decorator_name_array[3]);
177178
dec1.parse(input);
178179
EXPECT_TRUE(dec1.is_decorator(decorator_array[0]));
179180
EXPECT_TRUE(dec1.is_decorator(decorator_array[3]));

test/hotspot/gtest/logging/test_logMessageTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,12 @@ TEST_VM_F(LogMessageTest, long_message) {
146146
char* data = NEW_C_HEAP_ARRAY(char, size, mtLogging);
147147

148148
// fill buffer with start_marker...some data...end_marker
149-
sprintf(data, "%s", start_marker);
149+
os::snprintf_checked(data, size, "%s", start_marker);
150150
for (size_t i = strlen(start_marker); i < size; i++) {
151151
data[i] = '0' + (i % 10);
152152
}
153-
sprintf(data + size - strlen(end_marker) - 1, "%s", end_marker);
153+
size_t remaining_size = strlen(end_marker) + 1;
154+
os::snprintf_checked(data + size - remaining_size, remaining_size, "%s", end_marker);
154155

155156
msg.trace("%s", data); // Adds a newline, making the message exactly 10K in length.
156157
_log.write(msg);

0 commit comments

Comments
 (0)