]> Savannah Git Hosting - gnulib.git/commitdiff
fts: pacify GCC 12 -Wstrict-aliasing
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 4 Feb 2023 18:28:55 +0000 (10:28 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 4 Feb 2023 18:29:31 +0000 (10:29 -0800)
* lib/fts.c (ADJUST): Avoid -Wstrict-aliasing waring.

ChangeLog
lib/fts.c

index ed999a6d50bb7dd643f68c257dbd39d97c7229e5..ab24baf6f9596174520e0fbc8835e277d38c35b9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        (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  <bruno@clisp.org>
index 3e5bb47aaf0bfbb2141693d79e6077ace692aa65..78584b29022c8197c29f89f8050c10e3abae93db 100644 (file)
--- 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)