From c50c5ea436adba4b3c6cd1b1d9017adc9f16926d Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 12 Nov 2021 15:55:33 +0100 Subject: [PATCH] pkg/spifs: silence -Wcast-align --- pkg/spiffs/Makefile | 2 ++ pkg/spiffs/fs/spiffs_fs.c | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/spiffs/Makefile b/pkg/spiffs/Makefile index 8ab66b4bff..36b1893c7f 100644 --- a/pkg/spiffs/Makefile +++ b/pkg/spiffs/Makefile @@ -8,5 +8,7 @@ include $(RIOTBASE)/pkg/pkg.mk # Disable 'ISO C99 doesn’t support unnamed structs/unions [-Werror=pedantic]' CFLAGS += -Wno-pedantic +CFLAGS += -Wno-cast-align + all: $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/src -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_NAME) diff --git a/pkg/spiffs/fs/spiffs_fs.c b/pkg/spiffs/fs/spiffs_fs.c index f9d3d60bdf..055b93f6ea 100644 --- a/pkg/spiffs/fs/spiffs_fs.c +++ b/pkg/spiffs/fs/spiffs_fs.c @@ -355,10 +355,17 @@ static int _fstat(vfs_file_t *filp, struct stat *buf) return spiffs_err_to_errno(ret); } +static spiffs_DIR * _get_spifs_dir(vfs_DIR *dirp) +{ + /* the private buffer is part of a union that also contains a + * void pointer, hence, it is naturally aligned */ + return (spiffs_DIR *)(uintptr_t)&dirp->private_data.buffer[0]; +} + static int _opendir(vfs_DIR *dirp, const char *dirname, const char *abs_path) { spiffs_desc_t *fs_desc = dirp->mp->private_data; - spiffs_DIR *d = (spiffs_DIR *)&dirp->private_data.buffer[0]; + spiffs_DIR *d = _get_spifs_dir(dirp); (void) abs_path; spiffs_DIR *res = SPIFFS_opendir(&fs_desc->fs, dirname, d); @@ -371,7 +378,7 @@ static int _opendir(vfs_DIR *dirp, const char *dirname, const char *abs_path) static int _readdir(vfs_DIR *dirp, vfs_dirent_t *entry) { - spiffs_DIR *d = (spiffs_DIR *)&dirp->private_data.buffer[0]; + spiffs_DIR *d = _get_spifs_dir(dirp); struct spiffs_dirent e; struct spiffs_dirent *ret; @@ -396,7 +403,7 @@ static int _readdir(vfs_DIR *dirp, vfs_dirent_t *entry) static int _closedir(vfs_DIR *dirp) { - spiffs_DIR *d = (spiffs_DIR *)&dirp->private_data.buffer[0]; + spiffs_DIR *d = _get_spifs_dir(dirp); return spiffs_err_to_errno(SPIFFS_closedir(d)); }