[Reproducible-commits] [disorderfs] 01/06: Eliminate reinterpret_cast

Andrew Ayer agwa at andrewayer.name
Fri Jun 10 04:01:28 UTC 2016


This is an automated email from the git hooks/post-receive script.

agwa-guest pushed a commit to branch debian
in repository disorderfs.

commit 1f637fb4167c8830a09090075b90e16e99527611
Author: Andrew Ayer <agwa at andrewayer.name>
Date:   Thu Apr 7 20:51:01 2016 -0700

    Eliminate reinterpret_cast
---
 disorderfs.cpp | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/disorderfs.cpp b/disorderfs.cpp
index d56a14d..1e02aac 100644
--- a/disorderfs.cpp
+++ b/disorderfs.cpp
@@ -160,6 +160,22 @@ namespace {
 		}
 	};
 
+	template<class T> void set_fuse_data (struct fuse_file_info* fi, T data)
+	{
+		static_assert(sizeof(data) <= sizeof(fi->fh),
+			      "fuse_file_info::fh too small to store data");
+		std::memcpy(&fi->fh, &data, sizeof(data));
+	}
+
+	template<class T> T get_fuse_data (struct fuse_file_info* fi)
+	{
+		T data;
+		static_assert(sizeof(data) <= sizeof(fi->fh),
+			      "fuse_file_info::fh too small to store data");
+		std::memcpy(&data, &fi->fh, sizeof(data));
+		return data;
+	}
+
 	struct fuse_operations		disorderfs_fuse_operations;
 	enum {
 		KEY_HELP,
@@ -397,11 +413,11 @@ int	main (int argc, char** argv)
 			return -res;
 		}
 
-		info->fh = reinterpret_cast<uint64_t>(dirents.release());
+		set_fuse_data<Dirents*>(info, dirents.release());
 		return 0;
 	};
 	disorderfs_fuse_operations.readdir = [] (const char* path, void* buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* info) {
-		Dirents&		dirents = *reinterpret_cast<Dirents*>(info->fh);
+		Dirents&		dirents = *get_fuse_data<Dirents*>(info);
 		if (config.shuffle_dirents) {
 			std::random_device	rd;
 			std::mt19937		g(rd());
@@ -416,7 +432,7 @@ int	main (int argc, char** argv)
 		return 0;
 	};
 	disorderfs_fuse_operations.releasedir = [] (const char* path, struct fuse_file_info* info) -> int {
-		delete reinterpret_cast<Dirents*>(info->fh);
+		delete get_fuse_data<Dirents*>(info);
 		return 0;
 	};
 	disorderfs_fuse_operations.fsyncdir = [] (const char* path, int is_datasync, struct fuse_file_info* info) -> int {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/disorderfs.git



More information about the Reproducible-commits mailing list