From 38cfc591725de478879266584280562f0ba4b42f Mon Sep 17 00:00:00 2001 From: Xue-Lei Andrew Fan Date: Tue, 3 Jan 2023 22:44:14 +0000 Subject: [PATCH] 8299378: sprintf is deprecated in Xcode 14 Reviewed-by: kbarrett, dholmes --- test/hotspot/gtest/logging/test_logDecorators.cpp | 2 +- test/hotspot/gtest/logging/test_logMessageTest.cpp | 5 +++-- test/hotspot/gtest/utilities/test_unsigned5.cpp | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/hotspot/gtest/logging/test_logDecorators.cpp b/test/hotspot/gtest/logging/test_logDecorators.cpp index 1d04ca9e071..816959ead3c 100644 --- a/test/hotspot/gtest/logging/test_logDecorators.cpp +++ b/test/hotspot/gtest/logging/test_logDecorators.cpp @@ -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])); diff --git a/test/hotspot/gtest/logging/test_logMessageTest.cpp b/test/hotspot/gtest/logging/test_logMessageTest.cpp index 8aba848c9ab..d71a528e2ed 100644 --- a/test/hotspot/gtest/logging/test_logMessageTest.cpp +++ b/test/hotspot/gtest/logging/test_logMessageTest.cpp @@ -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); diff --git a/test/hotspot/gtest/utilities/test_unsigned5.cpp b/test/hotspot/gtest/utilities/test_unsigned5.cpp index 2b634500335..da3927e5bb2 100644 --- a/test/hotspot/gtest/utilities/test_unsigned5.cpp +++ b/test/hotspot/gtest/utilities/test_unsigned5.cpp @@ -23,6 +23,7 @@ #include "precompiled.hpp" #include "memory/allocation.hpp" +#include "runtime/os.hpp" #include "utilities/unsigned5.hpp" #include "unittest.hpp" @@ -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); }