From: Paul Eggert Date: Sat, 4 Feb 2023 18:28:55 +0000 (-0800) Subject: fts: pacify GCC 12 -Wstrict-aliasing X-Git-Tag: v1.0~1711 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=32c16c45d7378b014d9aac6130104c4d02a9acdb;p=gnulib.git fts: pacify GCC 12 -Wstrict-aliasing * lib/fts.c (ADJUST): Avoid -Wstrict-aliasing waring. --- 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)