Skip to content

Commit 38cfc59

Browse files
committed
8299378: sprintf is deprecated in Xcode 14
Reviewed-by: kbarrett, dholmes
1 parent ea25a56 commit 38cfc59

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

test/hotspot/gtest/logging/test_logDecorators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ TEST(LogDecorators, combine_with) {
174174

175175
// Select first and third decorator for dec1
176176
char input[64];
177-
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]);
178178
dec1.parse(input);
179179
EXPECT_TRUE(dec1.is_decorator(decorator_array[0]));
180180
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);

test/hotspot/gtest/utilities/test_unsigned5.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "precompiled.hpp"
2525
#include "memory/allocation.hpp"
26+
#include "runtime/os.hpp"
2627
#include "utilities/unsigned5.hpp"
2728
#include "unittest.hpp"
2829

@@ -251,7 +252,7 @@ TEST_VM(unsigned5, reader) {
251252
printer.print_on(&st, 4, "(", ")");
252253
std::string st_s(st.base(), st.size());
253254
char buf2[sizeof(stbuf)];
254-
sprintf(buf2, "(%d %d %d %d)", ints[0], ints[1], ints[2], ints[3]);
255+
os::snprintf_checked(buf2, sizeof(buf2), "(%d %d %d %d)", ints[0], ints[1], ints[2], ints[3]);
255256
std::string exp_s(buf2, strlen(buf2));
256257
ASSERT_EQ(exp_s, st_s);
257258
}

0 commit comments

Comments
 (0)