From: Josef 'Jeff' Sipek Date: Tue, 21 Jul 2020 17:18:41 +0000 (-0400) Subject: lib-fs: sis - Use container_of() instead of casts X-Git-Tag: 2.3.13~426 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=efad611e184d364afb85ffc9277d6985fb36569d;p=thirdparty%2Fdovecot%2Fcore.git lib-fs: sis - Use container_of() instead of casts Being more explicit not only makes the code more explict, it makes it safer. --- diff --git a/src/lib-fs/fs-sis.c b/src/lib-fs/fs-sis.c index 0a6ee82ff7..b3176a7603 100644 --- a/src/lib-fs/fs-sis.c +++ b/src/lib-fs/fs-sis.c @@ -27,6 +27,9 @@ struct sis_fs_file { bool opened; }; +#define SIS_FS(ptr) container_of((ptr), struct sis_fs, fs) +#define SIS_FILE(ptr) container_of((ptr), struct sis_fs_file, file) + static struct fs *fs_sis_alloc(void) { struct sis_fs *fs; @@ -69,7 +72,7 @@ fs_sis_init(struct fs *_fs, const char *args, const struct fs_settings *set, static void fs_sis_free(struct fs *_fs) { - struct sis_fs *fs = (struct sis_fs *)_fs; + struct sis_fs *fs = SIS_FS(_fs); fs_deinit(&_fs->parent); i_free(fs); @@ -85,8 +88,8 @@ static void fs_sis_file_init(struct fs_file *_file, const char *path, enum fs_open_mode mode, enum fs_open_flags flags) { - struct sis_fs_file *file = (struct sis_fs_file *)_file; - struct sis_fs *fs = (struct sis_fs *)_file->fs; + struct sis_fs_file *file = SIS_FILE(_file); + struct sis_fs *fs = SIS_FS(_file->fs); const char *dir, *hash; file->file.path = i_strdup(path); @@ -120,7 +123,7 @@ fs_sis_file_init(struct fs_file *_file, const char *path, static void fs_sis_file_deinit(struct fs_file *_file) { - struct sis_fs_file *file = (struct sis_fs_file *)_file; + struct sis_fs_file *file = SIS_FILE(_file); fs_file_deinit(&file->hash_file); fs_file_free(_file); @@ -132,7 +135,7 @@ static void fs_sis_file_deinit(struct fs_file *_file) static void fs_sis_file_close(struct fs_file *_file) { - struct sis_fs_file *file = (struct sis_fs_file *)_file; + struct sis_fs_file *file = SIS_FILE(_file); i_stream_unref(&file->hash_input); fs_file_close(file->hash_file); @@ -244,7 +247,7 @@ static void fs_sis_replace_hash_file(struct sis_fs_file *file) static int fs_sis_write(struct fs_file *_file, const void *data, size_t size) { - struct sis_fs_file *file = (struct sis_fs_file *)_file; + struct sis_fs_file *file = SIS_FILE(_file); if (_file->parent == NULL) return -1; @@ -267,7 +270,7 @@ static int fs_sis_write(struct fs_file *_file, const void *data, size_t size) static void fs_sis_write_stream(struct fs_file *_file) { - struct sis_fs_file *file = (struct sis_fs_file *)_file; + struct sis_fs_file *file = SIS_FILE(_file); i_assert(_file->output == NULL); @@ -290,7 +293,7 @@ static void fs_sis_write_stream(struct fs_file *_file) static int fs_sis_write_stream_finish(struct fs_file *_file, bool success) { - struct sis_fs_file *file = (struct sis_fs_file *)_file; + struct sis_fs_file *file = SIS_FILE(_file); if (!success) { if (_file->parent != NULL)