From 32c16c45d7378b014d9aac6130104c4d02a9acdb Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 4 Feb 2023 10:28:55 -0800 Subject: [PATCH 2/2] fts: pacify GCC 12 -Wstrict-aliasing * lib/fts.c (ADJUST): Avoid -Wstrict-aliasing waring. --- ChangeLog | 5 ++++- lib/fts.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed999a6d50..ab24baf6f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,10 @@ (fts_build): Do not access freed pointer directly; instead, save its bit-pattern into a uintptr_t, and use that to compare. (ADJUST): Likewise, but more trickily since this hack - puns pointer types and relies on undefined behavior. + actually accesses freed pointers, but does so in a way that + I hope GCC doesn’t notice. Although using ‘*(uintptr_t *) &P’ + instead of ‘(uintptr_t) P’ would avoid accessing freed pointers, + it would provoke a -Wstrict-aliasing diagnostic. * modules/fts (Depends-on): Add stdint. 2023-02-04 Bruno Haible diff --git a/lib/fts.c b/lib/fts.c index 3e5bb47aaf..78584b2902 100644 --- a/lib/fts.c +++ b/lib/fts.c @@ -1993,10 +1993,10 @@ fts_padjust (FTS *sp, FTSENT *head) trick does not work on your platform, please report a bug. */ #define ADJUST(p) do { \ - uintptr_t old_accpath = *(uintptr_t *) &(p)->fts_accpath; \ + uintptr_t old_accpath = (uintptr_t) (p)->fts_accpath; \ if (old_accpath != (uintptr_t) (p)->fts_name) { \ (p)->fts_accpath = \ - addr + (old_accpath - *(uintptr_t *) &(p)->fts_path); \ + addr + (old_accpath - (uintptr_t) (p)->fts_path); \ } \ (p)->fts_path = addr; \ } while (0) -- 2.37.2