Skip to content

Commit

Permalink
8299378: sprintf is deprecated in Xcode 14
Browse files Browse the repository at this point in the history
Reviewed-by: kbarrett, dholmes
  • Loading branch information
XueleiFan committed Jan 3, 2023
1 parent ea25a56 commit 38cfc59
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/hotspot/gtest/logging/test_logDecorators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ TEST(LogDecorators, combine_with) {

// Select first and third decorator for dec1
char input[64];
sprintf(input, "%s,%s", decorator_name_array[0], decorator_name_array[3]);
os::snprintf_checked(input, sizeof(input), "%s,%s", decorator_name_array[0], decorator_name_array[3]);
dec1.parse(input);
EXPECT_TRUE(dec1.is_decorator(decorator_array[0]));
EXPECT_TRUE(dec1.is_decorator(decorator_array[3]));
Expand Down
5 changes: 3 additions & 2 deletions test/hotspot/gtest/logging/test_logMessageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ TEST_VM_F(LogMessageTest, long_message) {
char* data = NEW_C_HEAP_ARRAY(char, size, mtLogging);

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

msg.trace("%s", data); // Adds a newline, making the message exactly 10K in length.
_log.write(msg);
Expand Down
3 changes: 2 additions & 1 deletion test/hotspot/gtest/utilities/test_unsigned5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "precompiled.hpp"
#include "memory/allocation.hpp"
#include "runtime/os.hpp"
#include "utilities/unsigned5.hpp"
#include "unittest.hpp"

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

1 comment on commit 38cfc59

@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.