diff --git a/dbms/src/AggregateFunctions/AggregateFunctionArray.h b/dbms/src/AggregateFunctions/AggregateFunctionArray.h index 8dda1be518a..f52d52e9745 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionArray.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionArray.h @@ -22,6 +22,8 @@ #include #include +#include + namespace DB { @@ -70,7 +72,7 @@ class AggregateFunctionArray final : public IAggregateFunctionHelper nested(num_arguments); for (size_t i = 0; i < num_arguments; ++i) nested[i] = &static_cast(*columns[i]).getData(); @@ -94,7 +96,7 @@ class AggregateFunctionArray final : public IAggregateFunctionHelperadd(place, nested, i, arena); + nested_func->add(place, nested.data(), i, arena); } diff --git a/dbms/src/AggregateFunctions/AggregateFunctionForEach.h b/dbms/src/AggregateFunctions/AggregateFunctionForEach.h index 46487824b94..4b1d275fdc1 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionForEach.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionForEach.h @@ -25,6 +25,8 @@ #include #include +#include + namespace DB { @@ -152,7 +154,7 @@ class AggregateFunctionForEach final void add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena * arena) const override { - const IColumn * nested[num_arguments]; + std::vector nested(num_arguments); for (size_t i = 0; i < num_arguments; ++i) nested[i] = &static_cast(*columns[i]).getData(); @@ -180,7 +182,7 @@ class AggregateFunctionForEach final char * nested_state = state.array_of_aggregate_datas; for (size_t i = begin; i < end; ++i) { - nested_func->add(nested_state, nested, i, arena); + nested_func->add(nested_state, nested.data(), i, arena); nested_state += nested_size_of_data; } } diff --git a/dbms/src/AggregateFunctions/AggregateFunctionNull.h b/dbms/src/AggregateFunctions/AggregateFunctionNull.h index ce160ba38f2..e00ad223181 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionNull.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionNull.h @@ -35,6 +35,7 @@ #include #include +#include namespace DB { @@ -473,7 +474,7 @@ class AggregateFunctionNullVariadic final void add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena * arena) const override { /// This container stores the columns we really pass to the nested function. - const IColumn * nested_columns[number_of_arguments]; + std::vector nested_columns(number_of_arguments); for (size_t i = 0; i < number_of_arguments; ++i) { @@ -493,7 +494,7 @@ class AggregateFunctionNullVariadic final } this->setFlag(place); - this->nested_function->add(this->nestedPlace(place), nested_columns, row_num, arena); + this->nested_function->add(this->nestedPlace(place), nested_columns.data(), row_num, arena); } bool allocatesMemoryInArena() const override { return this->nested_function->allocatesMemoryInArena(); } diff --git a/dbms/src/Common/CPUAffinityManager.h b/dbms/src/Common/CPUAffinityManager.h index c3069a211d3..ffc69c418f8 100644 --- a/dbms/src/Common/CPUAffinityManager.h +++ b/dbms/src/Common/CPUAffinityManager.h @@ -17,6 +17,7 @@ #include #include +#include #include #include #include diff --git a/dbms/src/Common/tests/gtest_bitpacking_primitives.cpp b/dbms/src/Common/tests/gtest_bitpacking_primitives.cpp index 03a7a0c2a36..695f9a57223 100644 --- a/dbms/src/Common/tests/gtest_bitpacking_primitives.cpp +++ b/dbms/src/Common/tests/gtest_bitpacking_primitives.cpp @@ -181,15 +181,15 @@ try auto test_func = [](const T * values, size_t size) { const auto width = BitpackingPrimitives::minimumBitWidth(values, size); const auto length = BitpackingPrimitives::getRequiredSize(size, width); - unsigned char buffer[length]; - BitpackingPrimitives::packBuffer(buffer, values, size, width); + std::vector buffer(length); + BitpackingPrimitives::packBuffer(buffer.data(), values, size, width); // dest buffer should be rounded up to group size const auto round_count = BitpackingPrimitives::roundUpToAlgorithmGroupSize(size); - unsigned char decoded[sizeof(T) * round_count]; - BitpackingPrimitives::unPackBuffer(decoded, buffer, size, width); + std::vector decoded(sizeof(T) * round_count); + BitpackingPrimitives::unPackBuffer(decoded.data(), buffer.data(), size, width); for (size_t i = 0; i < size; ++i) { - auto decode_value = unalignedLoad(decoded + i * sizeof(T)); + auto decode_value = unalignedLoad(decoded.data() + i * sizeof(T)); ASSERT_EQ(decode_value, values[i]); } }; diff --git a/dbms/src/DataStreams/JSONEachRowRowInputStream.cpp b/dbms/src/DataStreams/JSONEachRowRowInputStream.cpp index 2de7b3c7707..8b8b7c79293 100644 --- a/dbms/src/DataStreams/JSONEachRowRowInputStream.cpp +++ b/dbms/src/DataStreams/JSONEachRowRowInputStream.cpp @@ -17,6 +17,8 @@ #include #include +#include + namespace DB { @@ -100,8 +102,7 @@ bool JSONEachRowRowInputStream::read(MutableColumns & columns) /// Set of columns for which the values were read. The rest will be filled with default values. /// TODO Ability to provide your DEFAULTs. - bool read_columns[num_columns]; - memset(read_columns, 0, num_columns); + BoolVec read_columns(num_columns, false); bool first = true; while (true) diff --git a/dbms/src/Functions/FunctionsGeo.h b/dbms/src/Functions/FunctionsGeo.h index 185697ef9fa..971bf0c47a2 100644 --- a/dbms/src/Functions/FunctionsGeo.h +++ b/dbms/src/Functions/FunctionsGeo.h @@ -26,6 +26,7 @@ #include #include +#include #define DEGREES_IN_RADIANS (M_PI / 180.0) #define EARTH_RADIUS_IN_METERS 6372797.560856 @@ -257,7 +258,7 @@ class FunctionPointInEllipses : public IFunction /// Prepare array of ellipses. size_t ellipses_count = (arguments.size() - 2) / 4; - Ellipse ellipses[ellipses_count]; + std::vector ellipses(ellipses_count); for (const auto ellipse_idx : ext::range(0, ellipses_count)) { @@ -314,7 +315,7 @@ class FunctionPointInEllipses : public IFunction dst_data[row] = isPointInEllipses( col_vec_x->getData()[row], col_vec_y->getData()[row], - ellipses, + ellipses.data(), ellipses_count, start_index); } @@ -329,7 +330,7 @@ class FunctionPointInEllipses : public IFunction UInt8 res = isPointInEllipses( col_const_x->getValue(), col_const_y->getValue(), - ellipses, + ellipses.data(), ellipses_count, start_index); block.getByPosition(result).column = DataTypeUInt8().createColumnConst(size, UInt64(res)); diff --git a/dbms/src/IO/Checksum/tests/gtest_dm_checksum_buffer.cpp b/dbms/src/IO/Checksum/tests/gtest_dm_checksum_buffer.cpp index e8f9d428efb..628ba93c65b 100644 --- a/dbms/src/IO/Checksum/tests/gtest_dm_checksum_buffer.cpp +++ b/dbms/src/IO/Checksum/tests/gtest_dm_checksum_buffer.cpp @@ -336,7 +336,7 @@ void runStackedSeekingTest() auto x = buffer->count(); // compressed position auto y = compression_buffer.offset(); // uncompressed position compression_buffer.write(slice.data(), slice.size()); - slices.template emplace_back(std::move(slice), x, y); + slices.emplace_back(std::move(slice), x, y); } } { diff --git a/dbms/src/IO/Compression/EncodingUtil.cpp b/dbms/src/IO/Compression/EncodingUtil.cpp index 6d98df1418f..61badea250b 100644 --- a/dbms/src/IO/Compression/EncodingUtil.cpp +++ b/dbms/src/IO/Compression/EncodingUtil.cpp @@ -370,18 +370,17 @@ void deltaFORDecoding(const char * src, UInt32 source_size, char * dest, auto round_size = BitpackingPrimitives::roundUpToAlgorithmGroupSize(deltas_count); // Reserve enough space for the temporary buffer. const auto required_size = round_size * TYPE_BYTE_SIZE + TYPE_BYTE_SIZE; - char tmp_buffer[required_size]; - memset(tmp_buffer, 0, required_size); + std::vector tmp_buffer(required_size, 0); // copy the first value to the temporary buffer - memcpy(tmp_buffer, src, TYPE_BYTE_SIZE); + memcpy(tmp_buffer.data(), src, TYPE_BYTE_SIZE); FORDecoding( src + TYPE_BYTE_SIZE, source_size - TYPE_BYTE_SIZE, - tmp_buffer + TYPE_BYTE_SIZE, + tmp_buffer.data() + TYPE_BYTE_SIZE, required_size - TYPE_BYTE_SIZE); - auto * deltas = reinterpret_cast(tmp_buffer + TYPE_BYTE_SIZE); + auto * deltas = reinterpret_cast(tmp_buffer.data() + TYPE_BYTE_SIZE); zigZagDecoding(deltas, deltas_count, deltas); - deltaDecoding(tmp_buffer, dest_size, dest); + deltaDecoding(tmp_buffer.data(), dest_size, dest); } template <> @@ -400,18 +399,17 @@ void deltaFORDecoding(const char * src, UInt32 source_size, char * dest, const auto round_size = BitpackingPrimitives::roundUpToAlgorithmGroupSize(deltas_count); // Reserve enough space for the temporary buffer. const auto required_size = round_size * TYPE_BYTE_SIZE + TYPE_BYTE_SIZE; - char tmp_buffer[required_size]; - memset(tmp_buffer, 0, required_size); + std::vector tmp_buffer(required_size, 0); // copy the first value to the temporary buffer - memcpy(tmp_buffer, src, TYPE_BYTE_SIZE); + memcpy(tmp_buffer.data(), src, TYPE_BYTE_SIZE); FORDecoding( src + TYPE_BYTE_SIZE, source_size - TYPE_BYTE_SIZE, - tmp_buffer + TYPE_BYTE_SIZE, + tmp_buffer.data() + TYPE_BYTE_SIZE, required_size - TYPE_BYTE_SIZE); - auto * deltas = reinterpret_cast(tmp_buffer + TYPE_BYTE_SIZE); + auto * deltas = reinterpret_cast(tmp_buffer.data() + TYPE_BYTE_SIZE); zigZagDecoding(deltas, deltas_count, deltas); - deltaDecoding(tmp_buffer, dest_size, dest); + deltaDecoding(tmp_buffer.data(), dest_size, dest); } /// Run-length encoding diff --git a/dbms/src/IO/Compression/EncodingUtil.h b/dbms/src/IO/Compression/EncodingUtil.h index 7f544d0ea7f..49ec90a7c55 100644 --- a/dbms/src/IO/Compression/EncodingUtil.h +++ b/dbms/src/IO/Compression/EncodingUtil.h @@ -134,10 +134,14 @@ void FORDecoding(const char * src, UInt32 source_size, char * dest, UInt32 dest_ if (round_size != count) { // Reserve enough space for the temporary buffer. - unsigned char tmp_buffer[round_size * BYTES_SIZE]; - BitpackingPrimitives::unPackBuffer(tmp_buffer, reinterpret_cast(src), count, width); - applyFrameOfReference(reinterpret_cast(tmp_buffer), frame_of_reference, count); - memcpy(dest, tmp_buffer, dest_size); + std::vector tmp_buffer(round_size * BYTES_SIZE); + BitpackingPrimitives::unPackBuffer( + tmp_buffer.data(), + reinterpret_cast(src), + count, + width); + applyFrameOfReference(reinterpret_cast(tmp_buffer.data()), frame_of_reference, count); + memcpy(dest, tmp_buffer.data(), dest_size); return; } BitpackingPrimitives::unPackBuffer( diff --git a/dbms/src/IO/Encryption/AESCTRCipher.cpp b/dbms/src/IO/Encryption/AESCTRCipher.cpp index fb43a6f37e0..a5026ee027a 100644 --- a/dbms/src/IO/Encryption/AESCTRCipher.cpp +++ b/dbms/src/IO/Encryption/AESCTRCipher.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -25,7 +26,7 @@ #define InitCipherContext(ctx) \ EVP_CIPHER_CTX ctx##_var; \ - ctx = &ctx##_var; \ + (ctx) = &ctx##_var; \ EVP_CIPHER_CTX_init(ctx); // do nothing @@ -160,7 +161,9 @@ void OpenSSLCipher( uint64_t data_offset = 0; size_t remaining_data_size = data_size; int output_size = 0; - unsigned char partial_block[block_size]; + // Block size is always 16 bytes (128-bit) for AES + assert(block_size == AES_BLOCK_SIZE); + unsigned char partial_block[AES_BLOCK_SIZE]; int ret = 1; EVP_CIPHER_CTX * ctx = nullptr; @@ -249,7 +252,9 @@ void GMSSLSM4Cipher( uint64_t data_offset = 0; size_t remaining_data_size = data_size; - unsigned char partial_block[block_size]; + // Block size is always 16 bytes (128-bit) for SM4 + assert(block_size == SM4_BLOCK_SIZE); + unsigned char partial_block[SM4_BLOCK_SIZE]; // In the following we assume the encrypt/decrypt process allow in and out buffer are // the same, to save one memcpy. This is not specified in official man page. diff --git a/dbms/src/IO/Encryption/AESCTRCipherStream.cpp b/dbms/src/IO/Encryption/AESCTRCipherStream.cpp index dbf1f67bfd6..17d1cf4a4e6 100644 --- a/dbms/src/IO/Encryption/AESCTRCipherStream.cpp +++ b/dbms/src/IO/Encryption/AESCTRCipherStream.cpp @@ -14,6 +14,7 @@ #include #include +#include namespace DB @@ -43,7 +44,9 @@ void AESCTRCipherStream::encrypt(UInt64 file_offset, char * data, size_t data_si { const size_t block_size = DB::Encryption::blockSize(method); UInt64 block_index = file_offset / block_size; - unsigned char iv[block_size]; + // IV is always 16 bytes (128-bit) for AES and SM4 + assert(block_size == AES_BLOCK_SIZE); + unsigned char iv[AES_BLOCK_SIZE]; initIV(block_index, iv); DB::Encryption::Cipher(file_offset, data, data_size, key, method, iv, /*is_encrypt=*/true); } @@ -52,7 +55,9 @@ void AESCTRCipherStream::decrypt(UInt64 file_offset, char * data, size_t data_si { const size_t block_size = DB::Encryption::blockSize(method); UInt64 block_index = file_offset / block_size; - unsigned char iv[block_size]; + // IV is always 16 bytes (128-bit) for AES and SM4 + assert(block_size == AES_BLOCK_SIZE); + unsigned char iv[AES_BLOCK_SIZE]; initIV(block_index, iv); DB::Encryption::Cipher(file_offset, data, data_size, key, method, iv, /*is_encrypt=*/false); } diff --git a/dbms/src/IO/Encryption/tests/gtest_encryption_test.cpp b/dbms/src/IO/Encryption/tests/gtest_encryption_test.cpp index eddb9a2a4b1..2bd8be6f801 100644 --- a/dbms/src/IO/Encryption/tests/gtest_encryption_test.cpp +++ b/dbms/src/IO/Encryption/tests/gtest_encryption_test.cpp @@ -67,9 +67,9 @@ class EncryptionTest : public testing::TestWithParam own_iv(block_size); + memcpy(own_iv.data(), iv, block_size); + DB::Encryption::Cipher(0, ciphertext, MAX_SIZE, key, method, own_iv.data(), true); } void testEncryptionImpl(size_t start, size_t end, const unsigned char * iv, bool * success) @@ -188,13 +188,13 @@ try String key_str = DB::random::randomString(DB::Encryption::keySize(method)); size_t block_size = DB::Encryption::blockSize(method); String iv_str = DB::random::randomString(block_size); - unsigned char iv[block_size]; - memcpy(iv, iv_str.data(), block_size); - DB::Encryption::Cipher(0, text.data(), text.size(), key_str, method, iv, true); + std::vector iv(block_size); + memcpy(iv.data(), iv_str.data(), block_size); + DB::Encryption::Cipher(0, text.data(), text.size(), key_str, method, iv.data(), true); ASSERT_EQ(plaintext.size(), text.size()); ASSERT_NE(0, memcmp(plaintext.data(), text.data(), plaintext.size())); - memcpy(iv, iv_str.data(), block_size); - DB::Encryption::Cipher(0, text.data(), text.size(), key_str, method, iv, false); + memcpy(iv.data(), iv_str.data(), block_size); + DB::Encryption::Cipher(0, text.data(), text.size(), key_str, method, iv.data(), false); ASSERT_EQ(plaintext, text); } } @@ -245,8 +245,8 @@ try { size_t buff_size = 123; size_t buff_offset = 20; - char buff_write[buff_size]; - char buff_read[buff_size]; + std::vector buff_write(buff_size); + std::vector buff_read(buff_size); for (size_t i = 0; i < buff_size; i++) { @@ -256,9 +256,9 @@ try String file_path = tests::TiFlashTestEnv::getTemporaryPath("posix_wr_file"); WriteReadableFilePtr file = std::make_shared(file_path, true, -1, 0600, nullptr, nullptr); - ASSERT_EQ(buff_size, file->pwrite(buff_write, buff_size, buff_offset)); - ASSERT_EQ(buff_size, file->pread(buff_read, buff_size, buff_offset)); - ASSERT_EQ(strncmp(buff_write, buff_read, buff_size), 0); + ASSERT_EQ(buff_size, file->pwrite(buff_write.data(), buff_size, buff_offset)); + ASSERT_EQ(buff_size, file->pread(buff_read.data(), buff_size, buff_offset)); + ASSERT_EQ(strncmp(buff_write.data(), buff_read.data(), buff_size), 0); file->close(); ASSERT_TRUE(file->isClosed()); @@ -275,8 +275,8 @@ try { size_t buff_size = 123; size_t buff_offset = 20; - char buff_write[buff_size]; - char buff_read[buff_size]; + std::vector buff_write(buff_size); + std::vector buff_read(buff_size); for (size_t i = 0; i < buff_size; i++) { @@ -290,9 +290,9 @@ try WriteReadableFilePtr file = file_provider->newWriteReadableFile(file_path, EncryptionPath("encryption", "")); - ASSERT_EQ(buff_size, file->pwrite(buff_write, buff_size, buff_offset)); - ASSERT_EQ(buff_size, file->pread(buff_read, buff_size, buff_offset)); - ASSERT_EQ(strncmp(buff_write, buff_read, buff_size), 0); + ASSERT_EQ(buff_size, file->pwrite(buff_write.data(), buff_size, buff_offset)); + ASSERT_EQ(buff_size, file->pread(buff_read.data(), buff_size, buff_offset)); + ASSERT_EQ(strncmp(buff_write.data(), buff_read.data(), buff_size), 0); file->close(); ASSERT_TRUE(file->isClosed()); @@ -308,16 +308,16 @@ try { size_t buff_size = 123; size_t buff_offset = 20; - char buff_write[buff_size]; - char buff_read[buff_size]; - char buff_write_cpy[buff_size]; + std::vector buff_write(buff_size); + std::vector buff_read(buff_size); + std::vector buff_write_cpy(buff_size); for (size_t i = 0; i < buff_size; i++) { buff_write[i] = i % 0xFF; } - memcpy(buff_write_cpy, buff_write, buff_size); + memcpy(buff_write_cpy.data(), buff_write.data(), buff_size); String file_path = tests::TiFlashTestEnv::getTemporaryPath("enc_posix_wr_file"); @@ -330,9 +330,9 @@ try WriteReadableFilePtr file = file_provider->newWriteReadableFile(file_path, EncryptionPath("encryption", "")); - ASSERT_EQ(buff_size, file->pwrite(buff_write, buff_size, buff_offset)); - ASSERT_EQ(buff_size, file->pread(buff_read, buff_size, buff_offset)); - ASSERT_EQ(strncmp(buff_write_cpy, buff_read, buff_size), 0); + ASSERT_EQ(buff_size, file->pwrite(buff_write.data(), buff_size, buff_offset)); + ASSERT_EQ(buff_size, file->pread(buff_read.data(), buff_size, buff_offset)); + ASSERT_EQ(strncmp(buff_write_cpy.data(), buff_read.data(), buff_size), 0); file->close(); ASSERT_TRUE(file->isClosed()); @@ -361,19 +361,19 @@ try size_t buff_size = 123; size_t buff_offset = 20; - char buff_write[buff_size]; - char buff_read[buff_size]; - char buff_write_cpy[buff_size]; + std::vector buff_write(buff_size); + std::vector buff_read(buff_size); + std::vector buff_write_cpy(buff_size); for (size_t i = 0; i < buff_size; i++) { buff_write[i] = i % 0xFF; } - memcpy(buff_write_cpy, buff_write, buff_size); + memcpy(buff_write_cpy.data(), buff_write.data(), buff_size); - ASSERT_EQ(buff_size, enc_file->pwrite(buff_write, buff_size, buff_offset)); - ASSERT_EQ(buff_size, enc_file->pread(buff_read, buff_size, buff_offset)); - ASSERT_EQ(strncmp(buff_write_cpy, buff_read, buff_size), 0); + ASSERT_EQ(buff_size, enc_file->pwrite(buff_write.data(), buff_size, buff_offset)); + ASSERT_EQ(buff_size, enc_file->pread(buff_read.data(), buff_size, buff_offset)); + ASSERT_EQ(strncmp(buff_write_cpy.data(), buff_read.data(), buff_size), 0); enc_file->close(); ASSERT_TRUE(enc_file->isClosed()); @@ -405,7 +405,7 @@ class FtruncateTest : public ::testing::Test size_t buff_size = 123; size_t buff_need_delete_size = 23; - char buff_write[buff_size]; + std::vector buff_write(buff_size); size_t truncate_size = buff_size - buff_need_delete_size; @@ -414,7 +414,7 @@ class FtruncateTest : public ::testing::Test buff_write[i] = i % 0xFF; } - ASSERT_EQ(buff_size, file->pwrite(buff_write, buff_size, 0)); + ASSERT_EQ(buff_size, file->pwrite(buff_write.data(), buff_size, 0)); ASSERT_EQ(enc_file->fsync(), 0); ASSERT_EQ(enc_file->ftruncate(truncate_size), 0); ASSERT_EQ(Poco::File(file_path).getSize(), truncate_size); @@ -428,7 +428,7 @@ class FtruncateTest : public ::testing::Test { size_t buff_size = 123; size_t buff_need_delete_size = 23; - char buff_write[buff_size]; + std::vector buff_write(buff_size); size_t truncate_size = buff_size - buff_need_delete_size; @@ -440,7 +440,7 @@ class FtruncateTest : public ::testing::Test String file_path = tests::TiFlashTestEnv::getTemporaryPath(file_name); auto file = std::make_shared(file_path, true, -1, 0600); - ASSERT_EQ(buff_size, file->pwrite(buff_write, buff_size, 0)); + ASSERT_EQ(buff_size, file->pwrite(buff_write.data(), buff_size, 0)); ASSERT_EQ(file->fsync(), 0); ASSERT_EQ(file->ftruncate(truncate_size), 0); ASSERT_EQ(Poco::File(file_path).getSize(), truncate_size); @@ -464,7 +464,7 @@ TEST(PosixWritableFileTest, hardlink) try { size_t buff_size = 123; - char buff_write[buff_size]; + std::vector buff_write(buff_size); for (size_t i = 0; i < buff_size; i++) { @@ -473,7 +473,7 @@ try String file_path = tests::TiFlashTestEnv::getTemporaryPath("posix_file"); PosixWritableFile file(file_path, true, -1, 0600, nullptr); - auto n_write = file.write(buff_write, buff_size); + auto n_write = file.write(buff_write.data(), buff_size); ASSERT_EQ(n_write, buff_size); file.close(); @@ -495,12 +495,12 @@ try origin_file.remove(); // Read and check - char buff_read[buff_size]; + std::vector buff_read(buff_size); RandomAccessFilePtr file_for_read = std::make_shared(linked_file_path, -1, nullptr); - auto n_read = file_for_read->read(buff_read, buff_size); + auto n_read = file_for_read->read(buff_read.data(), buff_size); ASSERT_EQ(n_read, buff_size); file_for_read->close(); - ASSERT_EQ(strncmp(buff_write, buff_read, buff_size), 0); + ASSERT_EQ(strncmp(buff_write.data(), buff_read.data(), buff_size), 0); } CATCH @@ -521,17 +521,17 @@ try EncryptedWritableFile enc_file(file, cipher_stream); size_t buff_size = 123; - char buff_write[buff_size]; + std::vector buff_write(buff_size); for (size_t i = 0; i < buff_size; i++) { buff_write[i] = i % 0xFF; } - char buff_write_cpy[buff_size]; - memcpy(buff_write_cpy, buff_write, buff_size); + std::vector buff_write_cpy(buff_size); + memcpy(buff_write_cpy.data(), buff_write.data(), buff_size); - auto n_write = enc_file.write(buff_write_cpy, buff_size); + auto n_write = enc_file.write(buff_write_cpy.data(), buff_size); ASSERT_EQ(n_write, buff_size); enc_file.fsync(); enc_file.close(); @@ -556,14 +556,14 @@ try origin_file.remove(); // Read and check - char buff_read[buff_size]; + std::vector buff_read(buff_size); RandomAccessFilePtr file_for_read = std::make_shared(linked_file_path, -1, nullptr); EncryptedRandomAccessFile enc_file_for_read(file_for_read, cipher_stream); - n_write = enc_file_for_read.read(buff_read, buff_size); + n_write = enc_file_for_read.read(buff_read.data(), buff_size); ASSERT_EQ(n_write, buff_size); enc_file_for_read.close(); - ASSERT_EQ(strncmp(buff_write, buff_read, buff_size), 0); + ASSERT_EQ(strncmp(buff_write.data(), buff_read.data(), buff_size), 0); } CATCH diff --git a/dbms/src/Interpreters/Aggregator.cpp b/dbms/src/Interpreters/Aggregator.cpp index 36de37da77a..150aa3e0808 100644 --- a/dbms/src/Interpreters/Aggregator.cpp +++ b/dbms/src/Interpreters/Aggregator.cpp @@ -685,9 +685,9 @@ std::optional::Res try { if constexpr (only_lookup) - return state.template findKey(method.data, key_holder, hashval); + return state.findKey(method.data, key_holder, hashval); else - return state.template emplaceKey(method.data, key_holder, hashval); + return state.emplaceKey(method.data, key_holder, hashval); } catch (ResizeException &) { @@ -704,9 +704,9 @@ std::optional::Res try { if constexpr (only_lookup) - return state.template findKey(method.data, key_holder); + return state.findKey(method.data, key_holder); else - return state.template emplaceKey(method.data, key_holder); + return state.emplaceKey(method.data, key_holder); } catch (ResizeException &) { diff --git a/dbms/src/Interpreters/JoinPartition.cpp b/dbms/src/Interpreters/JoinPartition.cpp index 54faaae93a7..b0020287820 100644 --- a/dbms/src/Interpreters/JoinPartition.cpp +++ b/dbms/src/Interpreters/JoinPartition.cpp @@ -1411,7 +1411,7 @@ struct RowFlaggedHashMapAdder added_columns[j]->insertFrom( *current->block->getByPosition(right_indexes[j]).column.get(), current->row_num); - container.template push_back(reinterpret_cast(current)); + container.push_back(reinterpret_cast(current)); }; if unlikely ( probe_process_info.cache_columns_threshold > 0 && rows_joined >= probe_process_info.cache_columns_threshold) diff --git a/dbms/src/Storages/DeltaMerge/ColumnFile/ColumnFileTiny.cpp b/dbms/src/Storages/DeltaMerge/ColumnFile/ColumnFileTiny.cpp index 30e1516ce94..01c3715c8cc 100644 --- a/dbms/src/Storages/DeltaMerge/ColumnFile/ColumnFileTiny.cpp +++ b/dbms/src/Storages/DeltaMerge/ColumnFile/ColumnFileTiny.cpp @@ -23,6 +23,7 @@ #include #include +#include namespace DB::DM @@ -380,12 +381,12 @@ PageIdU64 ColumnFileTiny::writeColumnFileData( file_provider->createEncryptionInfo(ep); } - char page_data[data_size]; - buf->readStrict(page_data, data_size); + std::vector page_data(data_size); + buf->readStrict(page_data.data(), data_size); // encrypt the page data in place - file_provider->encryptPage(dm_context.keyspace_id, page_data, data_size, page_id); + file_provider->encryptPage(dm_context.keyspace_id, page_data.data(), data_size, page_id); // ReadBufferFromOwnString will copy the data, and own the data. - buf = std::make_shared(std::string_view(page_data, data_size)); + buf = std::make_shared(std::string_view(page_data.data(), data_size)); } wbs.log.putPage(page_id, 0, buf, data_size, col_data_sizes); diff --git a/dbms/src/Storages/DeltaMerge/Filter/ColumnRange_fwd.h b/dbms/src/Storages/DeltaMerge/Filter/ColumnRange_fwd.h index 0f6376ce4a4..ff7ea3d5efc 100644 --- a/dbms/src/Storages/DeltaMerge/Filter/ColumnRange_fwd.h +++ b/dbms/src/Storages/DeltaMerge/Filter/ColumnRange_fwd.h @@ -15,6 +15,7 @@ #pragma once #include +#include namespace DB::DM { diff --git a/dbms/src/Storages/Page/V2/tests/gtest_page_util.cpp b/dbms/src/Storages/Page/V2/tests/gtest_page_util.cpp index 26d091e1a4b..8af07676c06 100644 --- a/dbms/src/Storages/Page/V2/tests/gtest_page_util.cpp +++ b/dbms/src/Storages/Page/V2/tests/gtest_page_util.cpp @@ -36,7 +36,7 @@ try ::remove(FileName.c_str()); size_t buff_size = 1024; - char buff_write[buff_size]; + std::vector buff_write(buff_size); for (size_t i = 0; i < buff_size; i++) { @@ -46,7 +46,7 @@ try PageUtil::writeFile( file_for_write, 0, - buff_write, + buff_write.data(), buff_size, /*write_limiter*/ nullptr, /*background*/ false, @@ -55,10 +55,10 @@ try PageUtil::syncFile(file_for_write); file_for_write->close(); - char buff_read[buff_size]; + std::vector buff_read(buff_size); RandomAccessFilePtr file_for_read = std::make_shared(FileName, -1, nullptr); - PageUtil::readFile(file_for_read, 0, buff_read, buff_size, nullptr); - ASSERT_EQ(strcmp(buff_write, buff_read), 0); + PageUtil::readFile(file_for_read, 0, buff_read.data(), buff_size, nullptr); + ASSERT_EQ(strcmp(buff_write.data(), buff_read.data()), 0); ::remove(FileName.c_str()); } @@ -81,8 +81,8 @@ TEST(PageUtilsTest, BigReadWriteFile) { WritableFilePtr file_for_write = std::make_shared(FileName, true, -1, 0666); size_t buff_size = 13 * 1024 + 123; - char buff_write[buff_size]; - char buff_read[buff_size]; + std::vector buff_write(buff_size); + std::vector buff_read(buff_size); for (size_t i = 0; i < buff_size; i++) { @@ -92,7 +92,7 @@ TEST(PageUtilsTest, BigReadWriteFile) PageUtil::writeFile( file_for_write, 0, - buff_write, + buff_write.data(), buff_size, nullptr, /*background*/ false, @@ -102,8 +102,8 @@ TEST(PageUtilsTest, BigReadWriteFile) file_for_write->close(); RandomAccessFilePtr file_for_read = std::make_shared(FileName, -1, nullptr); - PageUtil::readFile(file_for_read, 0, buff_read, buff_size, nullptr); - ASSERT_EQ(strcmp(buff_write, buff_read), 0); + PageUtil::readFile(file_for_read, 0, buff_read.data(), buff_size, nullptr); + ASSERT_EQ(strcmp(buff_write.data(), buff_read.data()), 0); ::remove(FileName.c_str()); FailPointHelper::disableFailPoint(FailPoints::force_split_io_size_4k); diff --git a/dbms/src/Storages/Page/V3/tests/gtest_blob_store.cpp b/dbms/src/Storages/Page/V3/tests/gtest_blob_store.cpp index 26b89686654..ceb3449f775 100644 --- a/dbms/src/Storages/Page/V3/tests/gtest_blob_store.cpp +++ b/dbms/src/Storages/Page/V3/tests/gtest_blob_store.cpp @@ -172,8 +172,8 @@ try auto write_blob_datas = [](BlobStore & blob_store) { PageIdU64 page_id = 55; size_t buff_size = 1024; - char c_buff[buff_size]; - memset(c_buff, 0x1, buff_size); + std::vector c_buff(buff_size); + memset(c_buff.data(), 0x1, buff_size); // write blob 1 { @@ -181,7 +181,7 @@ try write_batch.putPage( page_id, /* tag */ 0, - std::make_shared(const_cast(c_buff), buff_size), + std::make_shared(c_buff.data(), buff_size), buff_size); blob_store.write(std::move(write_batch)); } @@ -192,7 +192,7 @@ try write_batch.putPage( page_id + 1, /* tag */ 0, - std::make_shared(const_cast(c_buff), buff_size), + std::make_shared(c_buff.data(), buff_size), buff_size); blob_store.write(std::move(write_batch)); } @@ -203,7 +203,7 @@ try write_batch.putPage( page_id + 2, /* tag */ 0, - std::make_shared(const_cast(c_buff), buff_size), + std::make_shared(c_buff.data(), buff_size), buff_size); blob_store.write(std::move(write_batch)); } @@ -352,7 +352,7 @@ TEST_F(BlobStoreTest, testWriteRead) size_t buff_size = 123; auto blob_store = BlobStore(getCurrentTestName(), file_provider, delegator, config, page_type_and_config); - char c_buff[buff_size * buff_nums]; + std::vector c_buff(buff_size * buff_nums); WriteBatch wb; @@ -363,8 +363,7 @@ TEST_F(BlobStoreTest, testWriteRead) c_buff[j + i * buff_size] = static_cast((j & 0xff) + i); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); wb.putPage(page_id++, /* tag */ 0, buff, buff_size); } @@ -372,7 +371,7 @@ TEST_F(BlobStoreTest, testWriteRead) PageEntriesEdit edit = blob_store.write(std::move(wb)); ASSERT_EQ(edit.size(), buff_nums); - char c_buff_read[buff_size * buff_nums]; + std::vector c_buff_read(buff_size * buff_nums); size_t index = 0; for (const auto & record : edit.getRecords()) @@ -387,11 +386,13 @@ TEST_F(BlobStoreTest, testWriteRead) buildV3Id(TEST_NAMESPACE_ID, page_id), record.entry.file_id, record.entry.offset, - c_buff_read + index * buff_size, + c_buff_read.data() + index * buff_size, record.entry.size, /* ReadLimiterPtr */ nullptr); - ASSERT_EQ(strncmp(c_buff + index * buff_size, c_buff_read + index * buff_size, record.entry.size), 0); + ASSERT_EQ( + strncmp(c_buff.data() + index * buff_size, c_buff_read.data() + index * buff_size, record.entry.size), + 0); index++; } ASSERT_EQ(index, buff_nums); @@ -412,7 +413,7 @@ TEST_F(BlobStoreTest, testWriteRead) { ASSERT_EQ(id, page_id++); ASSERT_EQ(page.data.size(), buff_size); - ASSERT_EQ(strncmp(c_buff + index * buff_size, page.data.begin(), page.data.size()), 0); + ASSERT_EQ(strncmp(c_buff.data() + index * buff_size, page.data.begin(), page.data.size()), 0); index++; } ASSERT_EQ(index, buff_nums); @@ -423,7 +424,7 @@ TEST_F(BlobStoreTest, testWriteRead) { auto page = blob_store.read(entry); ASSERT_EQ(page.data.size(), buff_size); - ASSERT_EQ(strncmp(c_buff + index * buff_size, page.data.begin(), page.data.size()), 0); + ASSERT_EQ(strncmp(c_buff.data() + index * buff_size, page.data.begin(), page.data.size()), 0); index++; } ASSERT_EQ(index, buff_nums); @@ -442,10 +443,10 @@ TEST_F(BlobStoreTest, testWriteReadWithIOLimiter) {PageType::RaftData, PageTypeConfig{.heavy_gc_valid_rate = config.heavy_gc_valid_rate_raft_data}}, }; auto blob_store = BlobStore(getCurrentTestName(), file_provider, delegator, config, page_type_and_config); - char c_buff[wb_nums * buff_size]; + std::vector c_buff(wb_nums * buff_size); - WriteBatch wbs[wb_nums]; - PageEntriesEdit edits[wb_nums]; + std::vector wbs(wb_nums); + std::vector edits(wb_nums); for (size_t i = 0; i < wb_nums; ++i) { @@ -454,8 +455,7 @@ TEST_F(BlobStoreTest, testWriteReadWithIOLimiter) c_buff[j + i * buff_size] = static_cast((j & 0xff) + i); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); wbs[i].putPage(page_id++, /* tag */ 0, buff, buff_size); } @@ -478,7 +478,7 @@ TEST_F(BlobStoreTest, testWriteReadWithIOLimiter) return consumed; }; - char c_buff_read[wb_nums * buff_size]; + std::vector c_buff_read(wb_nums * buff_size); { ReadLimiterPtr read_limiter = std::make_shared(get_stat, rate_target, LimiterType::UNKNOW); @@ -491,7 +491,7 @@ TEST_F(BlobStoreTest, testWriteReadWithIOLimiter) buildV3Id(TEST_NAMESPACE_ID, page_id), record.entry.file_id, record.entry.offset, - c_buff_read + i * buff_size, + c_buff_read.data() + i * buff_size, record.entry.size, read_limiter); } @@ -550,16 +550,16 @@ try WriteBatch wb; auto blob_store = BlobStore(getCurrentTestName(), file_provider, delegator, config, page_type_and_config); - char c_buff[buff_size]; + std::vector c_buff(buff_size); for (size_t j = 0; j < buff_size; ++j) { c_buff[j] = static_cast(j & 0xff); } - ReadBufferPtr buff1 = std::make_shared(const_cast(c_buff), buff_size); - ReadBufferPtr buff2 = std::make_shared(const_cast(c_buff), buff_size); - ReadBufferPtr buff3 = std::make_shared(const_cast(c_buff), buff_size); + ReadBufferPtr buff1 = std::make_shared(c_buff.data(), buff_size); + ReadBufferPtr buff2 = std::make_shared(c_buff.data(), buff_size); + ReadBufferPtr buff3 = std::make_shared(c_buff.data(), buff_size); wb.putPage(page_id1, /* tag */ 0, buff1, buff_size, {20, 40, 40, 20}); wb.putPage(page_id2, /* tag */ 0, buff2, buff_size, {10, 50, 20, 20, 20}); wb.putPage(page_id3, /* tag */ 0, buff3, buff_size, {10, 5, 20, 20, 15, 5, 15, 30}); @@ -584,7 +584,7 @@ try { ASSERT_EQ(page.page_id, page_id1); ASSERT_EQ(page.data.size(), buff_size); - ASSERT_EQ(strncmp(page.data.begin(), c_buff, buff_size), 0); + ASSERT_EQ(strncmp(page.data.begin(), c_buff.data(), buff_size), 0); } else if (pageid == page_id2) { @@ -625,7 +625,7 @@ TEST_F(BlobStoreTest, testFeildOffsetWriteRead) } auto blob_store = BlobStore(getCurrentTestName(), file_provider, delegator, config, page_type_and_config); - char c_buff[buff_size * buff_nums]; + std::vector c_buff(buff_size * buff_nums); WriteBatch wb; @@ -636,8 +636,7 @@ TEST_F(BlobStoreTest, testFeildOffsetWriteRead) c_buff[j + i * buff_size] = static_cast((j & 0xff) + i); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); wb.putPage(page_id++, /* tag */ 0, buff, buff_size, field_sizes); } @@ -645,7 +644,7 @@ TEST_F(BlobStoreTest, testFeildOffsetWriteRead) PageEntriesEdit edit = blob_store.write(std::move(wb)); ASSERT_EQ(edit.size(), buff_nums); - char c_buff_read[buff_size * buff_nums]; + std::vector c_buff_read(buff_size * buff_nums); size_t index = 0; for (const auto & record : edit.getRecords()) @@ -669,11 +668,13 @@ TEST_F(BlobStoreTest, testFeildOffsetWriteRead) buildV3Id(TEST_NAMESPACE_ID, page_id), record.entry.file_id, record.entry.offset, - c_buff_read + index * buff_size, + c_buff_read.data() + index * buff_size, record.entry.size, /* ReadLimiterPtr */ nullptr); - ASSERT_EQ(strncmp(c_buff + index * buff_size, c_buff_read + index * buff_size, record.entry.size), 0); + ASSERT_EQ( + strncmp(c_buff.data() + index * buff_size, c_buff_read.data() + index * buff_size, record.entry.size), + 0); index++; } ASSERT_EQ(index, buff_nums); @@ -797,8 +798,8 @@ TEST_F(BlobStoreTest, DISABLED_testWriteOutOfLimitSize) auto blob_store = BlobStore(getCurrentTestName(), file_provider, delegator, config, page_type_and_config); WriteBatch wb; - char c_buff[buff_size]; - ReadBufferPtr buff = std::make_shared(const_cast(c_buff), buff_size); + std::vector c_buff(buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data(), buff_size); wb.putPage(50, /*tag*/ 0, buff, buff_size); bool catch_exception = false; @@ -820,11 +821,11 @@ TEST_F(BlobStoreTest, DISABLED_testWriteOutOfLimitSize) { auto blob_store = BlobStore(getCurrentTestName(), file_provider, delegator, config, page_type_and_config); - char c_buff1[buf_size]; - char c_buff2[buf_size]; + std::vector c_buff1(buf_size); + std::vector c_buff2(buf_size); - ReadBufferPtr buff1 = std::make_shared(const_cast(c_buff1), buf_size); - ReadBufferPtr buff2 = std::make_shared(const_cast(c_buff2), buf_size); + ReadBufferPtr buff1 = std::make_shared(c_buff1.data(), buf_size); + ReadBufferPtr buff2 = std::make_shared(c_buff2.data(), buf_size); { WriteBatch wb; @@ -870,7 +871,7 @@ TEST_F(BlobStoreTest, testBlobStoreGcStats) std::list remove_entries_idx2 = {6, 8}; WriteBatch wb; - char c_buff[buff_size * buff_nums]; + std::vector c_buff(buff_size * buff_nums); { for (size_t i = 0; i < buff_nums; ++i) { @@ -878,8 +879,7 @@ TEST_F(BlobStoreTest, testBlobStoreGcStats) { c_buff[j + i * buff_size] = static_cast((j & 0xff) + i); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); wb.putPage(page_id, /* tag */ 0, buff, buff_size); } } @@ -966,7 +966,7 @@ TEST_F(BlobStoreTest, testBlobStoreGcStats2) std::list remove_entries_idx = {0, 1, 2, 3, 4, 5, 6, 7}; WriteBatch wb; - char c_buff[buff_size * buff_nums]; + std::vector c_buff(buff_size * buff_nums); { for (size_t i = 0; i < buff_nums; ++i) { @@ -974,8 +974,7 @@ TEST_F(BlobStoreTest, testBlobStoreGcStats2) { c_buff[j + i * buff_size] = static_cast((j & 0xff) + i); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); wb.putPage(page_id, /* tag */ 0, buff, buff_size); } } @@ -1028,7 +1027,7 @@ TEST_F(BlobStoreTest, testBlobStoreRaftDataGcStats) std::list remove_entries_idx = {0, 1, 2, 3, 4, 5, 6, 7}; WriteBatch wb; - char c_buff[buff_size * buff_nums]; + std::vector c_buff(buff_size * buff_nums); { for (size_t i = 0; i < buff_nums; ++i) { @@ -1036,8 +1035,7 @@ TEST_F(BlobStoreTest, testBlobStoreRaftDataGcStats) { c_buff[j + i * buff_size] = static_cast((j & 0xff) + i); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); wb.putPage(page_id, /* tag */ 0, buff, buff_size); } } @@ -1084,7 +1082,7 @@ TEST_F(BlobStoreTest, GC) size_t buff_size = 123; auto blob_store = BlobStore(getCurrentTestName(), file_provider, delegator, config, page_type_and_config); - char c_buff[buff_size * buff_nums]; + std::vector c_buff(buff_size * buff_nums); WriteBatch wb; @@ -1095,8 +1093,7 @@ TEST_F(BlobStoreTest, GC) c_buff[j + i * buff_size] = static_cast((j & 0xff) + i); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); wb.putPage(page_id++, /* tag */ 0, buff, buff_size); } @@ -1161,7 +1158,7 @@ try delegator, config_with_small_file_limit_size, page_type_and_config); - char c_buff[buff_size * buff_nums]; + std::vector c_buff(buff_size * buff_nums); PageDirectory::GcEntriesMap gc_context; @@ -1173,8 +1170,7 @@ try c_buff[j + i * buff_size] = static_cast((j & 0xff) + i); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); WriteBatch wb; wb.putPage(page_id, /* tag */ 0, buff, buff_size); PageEntriesEdit edit = blob_store.write(std::move(wb)); @@ -1220,7 +1216,7 @@ try delegator, config_with_small_file_limit_size, page_type_and_config); - char c_buff[buff_size * buff_nums]; + std::vector c_buff(buff_size * buff_nums); BlobStore::FieldReadInfos read_infos; @@ -1231,8 +1227,7 @@ try c_buff[j + i * buff_size] = static_cast(buildV3Id(TEST_NAMESPACE_ID, page_id + j)); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); PageFieldSizes field_sizes{1, 2, 4, 8, (buff_size - 1 - 2 - 4 - 8)}; WriteBatch wb; wb.putPage(page_id, /* tag */ 0, buff, buff_size, field_sizes); @@ -1649,10 +1644,10 @@ try { const size_t size_500 = 500; - char c_buff[size_500]; + std::vector c_buff(size_500); WriteBatch wb; - ReadBufferPtr buff = std::make_shared(const_cast(c_buff), size_500); + ReadBufferPtr buff = std::make_shared(c_buff.data(), size_500); wb.putPage(page_id, /* tag */ 0, buff, size_500); PageEntriesEdit edit = blob_store.write(std::move(wb)); @@ -1740,10 +1735,10 @@ try config_with_small_file_limit_size, page_type_and_config); size_t size_500 = 500; - char c_buff[size_500]; + std::vector c_buff(size_500); WriteBatch wb; - ReadBufferPtr buff = std::make_shared(const_cast(c_buff), size_500); + ReadBufferPtr buff = std::make_shared(c_buff.data(), size_500); wb.putPage(page_id, /* tag */ 0, buff, size_500); auto edit = blob_store.write(std::move(wb)); const auto & records = edit.getRecords(); @@ -1791,12 +1786,12 @@ try page_type_and_config); size_t size_500 = 500; size_t size_200 = 200; - char c_buff1[size_500]; - char c_buff2[size_200]; + std::vector c_buff1(size_500); + std::vector c_buff2(size_200); WriteBatch wb; - ReadBufferPtr buff1 = std::make_shared(const_cast(c_buff1), size_500); - ReadBufferPtr buff2 = std::make_shared(const_cast(c_buff2), size_200); + ReadBufferPtr buff1 = std::make_shared(c_buff1.data(), size_500); + ReadBufferPtr buff2 = std::make_shared(c_buff2.data(), size_200); wb.putPage(page_id, /* tag */ 0, buff1, size_500); wb.putPage(page_id + 1, /* tag */ 0, buff2, size_200); auto edit = blob_store.write(std::move(wb)); @@ -1833,10 +1828,10 @@ try // new write will create new blob file size_t size_100 = 100; - char c_buff[size_100]; + std::vector c_buff(size_100); WriteBatch wb; - ReadBufferPtr buff = std::make_shared(const_cast(c_buff), size_100); + ReadBufferPtr buff = std::make_shared(c_buff.data(), size_100); wb.putPage(page_id, /* tag */ 0, buff, size_100); auto edit = blob_store.write(std::move(wb)); const auto & records = edit.getRecords(); @@ -1875,14 +1870,14 @@ try size_t size_100 = 100; size_t size_500 = 500; size_t size_200 = 200; - char c_buff1[size_100]; - char c_buff2[size_500]; - char c_buff3[size_200]; + std::vector c_buff1(size_100); + std::vector c_buff2(size_500); + std::vector c_buff3(size_200); WriteBatch wb; - ReadBufferPtr buff1 = std::make_shared(const_cast(c_buff1), size_100); - ReadBufferPtr buff2 = std::make_shared(const_cast(c_buff2), size_500); - ReadBufferPtr buff3 = std::make_shared(const_cast(c_buff3), size_200); + ReadBufferPtr buff1 = std::make_shared(c_buff1.data(), size_100); + ReadBufferPtr buff2 = std::make_shared(c_buff2.data(), size_500); + ReadBufferPtr buff3 = std::make_shared(c_buff3.data(), size_200); wb.putPage(page_id1, /* tag */ 0, buff1, size_100); wb.putPage(page_id2, /* tag */ 0, buff2, size_500); wb.putPage(page_id3, /* tag */ 0, buff3, size_200); diff --git a/dbms/src/Storages/Page/V3/tests/gtest_page_storage.cpp b/dbms/src/Storages/Page/V3/tests/gtest_page_storage.cpp index 8adbf811ab2..1038920ffc8 100644 --- a/dbms/src/Storages/Page/V3/tests/gtest_page_storage.cpp +++ b/dbms/src/Storages/Page/V3/tests/gtest_page_storage.cpp @@ -102,10 +102,10 @@ try size_t buff_size = 100ul * 1024; const size_t rate_target = buff_size - 1; - char c_buff[wb_nums * buff_size]; + std::vector c_buff(wb_nums * buff_size); - WriteBatch wbs[wb_nums]; - u128::PageEntriesEdit edits[wb_nums]; + std::vector wbs(wb_nums); + std::vector edits(wb_nums); for (size_t i = 0; i < wb_nums; ++i) { @@ -114,8 +114,7 @@ try c_buff[j + i * buff_size] = static_cast((j & 0xff) + i); } - ReadBufferPtr buff - = std::make_shared(const_cast(c_buff + i * buff_size), buff_size); + ReadBufferPtr buff = std::make_shared(c_buff.data() + i * buff_size, buff_size); wbs[i].putPage(page_id + i, /* tag */ 0, buff, buff_size); } WriteLimiterPtr write_limiter = std::make_shared(rate_target, LimiterType::UNKNOW, 20); diff --git a/dbms/src/Storages/Page/V3/tests/gtest_wal_log.cpp b/dbms/src/Storages/Page/V3/tests/gtest_wal_log.cpp index a06a9094c7a..b0b693ecb05 100644 --- a/dbms/src/Storages/Page/V3/tests/gtest_wal_log.cpp +++ b/dbms/src/Storages/Page/V3/tests/gtest_wal_log.cpp @@ -208,10 +208,15 @@ class LogFileRWTest : public ::testing::TestWithParam> Format::ChecksumClass digest; size_t crc_buff_size = header_size - Format::CHECKSUM_START_OFFSET + payload_len; - char crc_buff[crc_buff_size]; - PageUtil::readFile(wr_file, header_offset + Format::CHECKSUM_START_OFFSET, crc_buff, crc_buff_size, nullptr); - - digest.update(crc_buff, crc_buff_size); + std::vector crc_buff(crc_buff_size); + PageUtil::readFile( + wr_file, + header_offset + Format::CHECKSUM_START_OFFSET, + crc_buff.data(), + crc_buff_size, + nullptr); + + digest.update(crc_buff.data(), crc_buff_size); auto checksum = digest.checksum(); PageUtil::writeFile(wr_file, header_offset, reinterpret_cast(&checksum), sizeof(checksum), nullptr);