From: Bruno Haible Date: Tue, 27 Aug 2024 20:08:00 +0000 (+0200) Subject: fts: Don't assume that a pointer is as wide as a 'long'. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=834946c12bac3aa3053bbebe5a49c4960f5c7fd2;p=gnulib.git 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/ChangeLog b/ChangeLog index 2e60f867e3..51e78323e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2024-08-27 Bruno Haible + + 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'. + 2024-08-27 Bruno Haible mkdir: Fix for use of posixcheck module on native Windows. 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);