From 834946c12bac3aa3053bbebe5a49c4960f5c7fd2 Mon Sep 17 00:00:00 2001 From: Bruno Haible <bruno@clisp.org> Date: Tue, 27 Aug 2024 22:08:00 +0200 Subject: [PATCH] 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'. --- ChangeLog | 5 +++++ lib/fts.c | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e60f867e3..51e78323e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2024-08-27 Bruno Haible <bruno@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'. + 2024-08-27 Bruno Haible <bruno@clisp.org> 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); -- 2.39.5