From 8d1cc39d8989cc2590597812e3bbb610fb246da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florin=20Cri=C8=99an?= Date: Tue, 15 Jun 2021 13:19:33 +0300 Subject: [PATCH] stringprintf_unittest.cc: Replace `new char[n+1]` with `std::array` Prefer safer alternative to naked pointers. This is a follow-up to 1dd313cd0611ac13257c075a977d46c874c42652 --- src/google/protobuf/stubs/stringprintf_unittest.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/stubs/stringprintf_unittest.cc b/src/google/protobuf/stubs/stringprintf_unittest.cc index a42f9457df41..63f38bfe1eb4 100644 --- a/src/google/protobuf/stubs/stringprintf_unittest.cc +++ b/src/google/protobuf/stubs/stringprintf_unittest.cc @@ -32,6 +32,7 @@ #include +#include #include #include @@ -108,14 +109,13 @@ TEST(StringPrintfTest, Multibyte) { // Repeat with longer string, to make sure that the dynamically // allocated path in StringAppendV is handled correctly. - int n = 2048; - char* buf = new char[n+1]; - memset(buf, ' ', n-3); - memcpy(buf + n - 3, kInvalidCodePoint, 4); - value = StringPrintf("%.*s", n, buf); + const size_t n = 2048; + std::array buf; + memset(&buf[0], ' ', n-3); + memcpy(&buf[0] + n - 3, kInvalidCodePoint, 4); + value = StringPrintf("%.*s", n, &buf[0]); // See GRTEv2 vs. GRTEv3 comment above. - EXPECT_TRUE(value.empty() || value == buf); - delete[] buf; + EXPECT_TRUE(value.empty() || value == &buf[0]); setlocale(LC_CTYPE, old_locale.c_str()); }