[PATCH 2/4] Fix warning about unaligned pointer in jffs2reader

Frederic Germain frederic.germain at gmail.com
Tue Nov 9 00:17:49 PST 2021


gcc 9.3.0-17ubuntu1~20.04 warning on time_t ctime value is :

Fix taking address of packed member of ‘struct jffs2_raw_inode’ may
result in an unaligned pointer value [-Waddress-of-packed-member].

Signed-off-by: Frederic Germain <frederic.germain at gmail.com>
---
 jffsX-utils/jffs2reader.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/jffsX-utils/jffs2reader.c b/jffsX-utils/jffs2reader.c
index 083500e..33c5577 100644
--- a/jffsX-utils/jffs2reader.c
+++ b/jffsX-utils/jffs2reader.c
@@ -336,8 +336,9 @@ static void printdir(char *o, size_t size, struct dir *d, const char *path,
 			d = d->next;
 			continue;
 		}
-
-		filetime = ctime((const time_t *) &(ri->ctime));
+		time_t _ctime;
+		memcpy(&_ctime, &(ri->ctime), sizeof(time_t));
+		filetime = ctime(&_ctime);
 		age = time(NULL) - je32_to_cpu(ri->ctime);
 		mode.v32 = ri->mode.m;
 		printf("%s %-4d %-8d %-8d ", mode_string(je32_to_cpu(mode)),
-- 
2.25.1




More information about the linux-mtd mailing list