From 58048dc178d5e4854e05fd4f39d32ecdeaad7f2f Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 17 Apr 2018 11:42:43 +0100 Subject: [PATCH] [file_utils] Use aligned memory in zero_superblock --- base/file_utils.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/base/file_utils.cc b/base/file_utils.cc index 7173000..ba8957c 100644 --- a/base/file_utils.cc +++ b/base/file_utils.cc @@ -144,10 +144,14 @@ file_utils::get_file_length(string const &file) { void file_utils::zero_superblock(std::string const &path) { + char *buffer; unsigned const SUPERBLOCK_SIZE = 4096; - char buffer[SUPERBLOCK_SIZE]; int fd = open_block_file(path, SUPERBLOCK_SIZE, true, true); + buffer = reinterpret_cast(aligned_alloc(SUPERBLOCK_SIZE, SUPERBLOCK_SIZE)); + if (!buffer) + throw runtime_error("out of memory"); + memset(buffer, 0, SUPERBLOCK_SIZE); if (::write(fd, buffer, SUPERBLOCK_SIZE) != SUPERBLOCK_SIZE) throw runtime_error("couldn't zero superblock");