diff --git a/src/IO/tests/gtest_peekable_read_buffer.cpp b/src/IO/tests/gtest_peekable_read_buffer.cpp index fc2b78c0eaf..70d073c8ba1 100644 --- a/src/IO/tests/gtest_peekable_read_buffer.cpp +++ b/src/IO/tests/gtest_peekable_read_buffer.cpp @@ -9,9 +9,9 @@ static void readAndAssert(DB::ReadBuffer & buf, const char * str) { size_t n = strlen(str); - char tmp[n]; - buf.readStrict(tmp, n); - ASSERT_EQ(strncmp(tmp, str, n), 0); + std::vector tmp(n); + buf.readStrict(tmp.data(), n); + ASSERT_EQ(strncmp(tmp.data(), str, n), 0); } static void assertAvailable(DB::ReadBuffer & buf, const char * str) diff --git a/utils/self-extracting-executable/compressor.cpp b/utils/self-extracting-executable/compressor.cpp index 642a4f1ab8e..337fe720a68 100644 --- a/utils/self-extracting-executable/compressor.cpp +++ b/utils/self-extracting-executable/compressor.cpp @@ -252,7 +252,7 @@ int compressFiles(const char* out_name, const char* exec, char* filenames[], int /// Store information about each file and compress it FileData* files_data = new FileData[count + is_exec]; - const char * names[count + is_exec]; + std::vector names(count + is_exec); for (int i = 0; i <= count; ++i) { const char* filename = nullptr; @@ -342,7 +342,7 @@ int compressFiles(const char* out_name, const char* exec, char* filenames[], int /// save location of files information metadata.start_of_files_data = htole64(pointer); - if (0 != saveMetaData(names, count + is_exec, output_fd, metadata, files_data, pointer, sum_file_size)) + if (0 != saveMetaData(names.data(), count + is_exec, output_fd, metadata, files_data, pointer, sum_file_size)) { delete [] files_data; return 1; diff --git a/utils/self-extracting-executable/decompressor.cpp b/utils/self-extracting-executable/decompressor.cpp index 071ecb066cb..1a5cd35a369 100644 --- a/utils/self-extracting-executable/decompressor.cpp +++ b/utils/self-extracting-executable/decompressor.cpp @@ -240,32 +240,32 @@ int decompressFiles(int input_fd, char * path, char * name, bool & have_compress size_t file_path_len = path ? strlen(path) + 1 + file_name_len : file_name_len; - char file_name[file_path_len]; - memset(file_name, '\0', file_path_len); + std::vector file_name(file_path_len); + memset(file_name.data(), '\0', file_path_len); if (path) { - strcat(file_name, path); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) - strcat(file_name, "/"); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) + strcat(file_name.data(), path); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) + strcat(file_name.data(), "/"); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) } bool same_name = false; if (file_info.exec) { has_exec = true; - strcat(file_name, name); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) + strcat(file_name.data(), name); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) } else { if (strcmp(name, input + files_pointer) == 0) same_name = true; - strcat(file_name, input + files_pointer); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) + strcat(file_name.data(), input + files_pointer); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) } files_pointer += le64toh(file_info.name_length); if (file_info.exec || same_name) { - strcat(file_name, ".decompressed.XXXXXX"); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) - int fd = mkstemp(file_name); + strcat(file_name.data(), ".decompressed.XXXXXX"); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) + int fd = mkstemp(file_name.data()); if (fd == -1) { perror("mkstemp"); @@ -273,12 +273,12 @@ int decompressFiles(int input_fd, char * path, char * name, bool & have_compress } if (0 != close(fd)) perror("close"); - strncpy(decompressed_suffix, file_name + strlen(file_name) - 6, 6); + strncpy(decompressed_suffix, file_name.data() + strlen(file_name.data()) - 6, 6); *decompressed_umask = le64toh(file_info.umask); have_compressed_analoge = true; } - int output_fd = open(file_name, O_RDWR | O_CREAT, le64toh(file_info.umask)); + int output_fd = open(file_name.data(), O_RDWR | O_CREAT, le64toh(file_info.umask)); if (output_fd == -1) { @@ -330,7 +330,7 @@ int decompressFiles(int input_fd, char * path, char * name, bool & have_compress perror("close"); if (is_sudo) - chown(file_name, info_in.st_uid, info_in.st_gid); + chown(file_name.data(), info_in.st_uid, info_in.st_gid); } if (0 != munmap(input, info_in.st_size)) @@ -415,19 +415,19 @@ int main(int/* argc*/, char* argv[]) return 1; } - char file_path[strlen(self) + 1]; - strcpy(file_path, self); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) + std::vector file_path(strlen(self) + 1); + strcpy(file_path.data(), self); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) char * path = nullptr; - char * name = strrchr(file_path, '/'); + char * name = strrchr(file_path.data(), '/'); if (name) { - path = file_path; + path = file_path.data(); *name = 0; ++name; } else - name = file_path; + name = file_path.data(); struct stat input_info; if (0 != stat(self, &input_info)) @@ -526,20 +526,20 @@ int main(int/* argc*/, char* argv[]) { const char * const decompressed_name_fmt = "%s.decompressed.%s"; int decompressed_name_len = snprintf(nullptr, 0, decompressed_name_fmt, self, decompressed_suffix); - char decompressed_name[decompressed_name_len + 1]; - (void)snprintf(decompressed_name, decompressed_name_len + 1, decompressed_name_fmt, self, decompressed_suffix); + std::vector decompressed_name(decompressed_name_len + 1); + (void)snprintf(decompressed_name.data(), decompressed_name_len + 1, decompressed_name_fmt, self, decompressed_suffix); #if defined(OS_DARWIN) // We can't just rename it on Mac due to security issues, so we copy it... std::error_code ec; - std::filesystem::copy_file(static_cast(decompressed_name), static_cast(self), ec); + std::filesystem::copy_file(static_cast(decompressed_name.data()), static_cast(self), ec); if (ec) { std::cerr << ec.message() << std::endl; return 1; } #else - if (link(decompressed_name, self)) + if (link(decompressed_name.data(), self)) { perror("link"); return 1; @@ -551,7 +551,7 @@ int main(int/* argc*/, char* argv[]) return 1; } - if (unlink(decompressed_name)) + if (unlink(decompressed_name.data())) { perror("unlink"); return 1;