clang on native Windows gives me these warnings:

gllib\fts.c(1867,16): warning: cast to smaller integer type 'long' from 'FTSENT 
**' (aka 'struct _ftsent **') [-Wpointer-to-int-cast]
gllib\fts.c(1867,37): warning: cast to smaller integer type 'long' from 'void 
*' [-Wvoid-pointer-to-int-cast]

Obviously this code was meant to be using an integer type as wide as a
pointer. (Otherwise it could have been using plain 'int'.) Nowadays, that
is [u]intptr_t, not 'long'.


2024-08-27  Bruno Haible  <br...@clisp.org>

        fts: Don't assume that a pointer is as wide as a 'long'.
        * lib/fts.c (fts_sort): Cast pointers to 'uintptr_t', not to 'long'.

diff --git a/lib/fts.c b/lib/fts.c
index 5a86419c74..92306bc72f 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1858,13 +1858,13 @@ fts_sort (FTS *sp, FTSENT *head, register size_t nitems)
            run-time representation, and one can convert sp->fts_compar to
            the type qsort expects without problem.  Use the heuristic that
            this is OK if the two pointer types are the same size, and if
-           converting FTSENT ** to long int is the same as converting
-           FTSENT ** to void * and then to long int.  This heuristic isn't
+           converting FTSENT ** to uintptr_t is the same as converting
+           FTSENT ** to void * and then to uintptr_t.  This heuristic isn't
            valid in general but we don't know of any counterexamples.  */
         FTSENT *dummy;
         int (*compare) (void const *, void const *) =
           ((sizeof &dummy == sizeof (void *)
-            && (long int) &dummy == (long int) (void *) &dummy)
+            && (uintptr_t) &dummy == (uintptr_t) (void *) &dummy)
            ? (int (*) (void const *, void const *)) sp->fts_compar
            : fts_compar);
 




Reply via email to