From 62d6c3303089d9c708527ab7bf98348a6429e8c3 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sun, 12 Feb 2023 14:10:34 +0300 Subject: mach, hurd: Cast through uintptr_t When casting between a pointer and an integer of a different size, GCC emits a warning (which is escalated to a build failure by -Werror). Indeed, if what you start with is a pointer, which you then cast to a shorter integer and then back again, you're going to cut off some bits of the pointer. But if you start with an integer (such as mach_port_t), then cast it to a longer pointer (void *), and then back to a shorter integer, you are fine. To keep GCC happy, cast through an intermediary uintptr_t, which is always the same size as a pointer. Signed-off-by: Sergey Bugaev Message-Id: <20230212111044.610942-4-bugaevc@gmail.com> --- htl/cthreads-compat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'htl') diff --git a/htl/cthreads-compat.c b/htl/cthreads-compat.c index 55043a8bb4..2a0a95b6ff 100644 --- a/htl/cthreads-compat.c +++ b/htl/cthreads-compat.c @@ -25,8 +25,9 @@ void __cthread_detach (__cthread_t thread) { int err; + pthread_t pthread = (pthread_t) (uintptr_t) thread; - err = __pthread_detach ((pthread_t) thread); + err = __pthread_detach (pthread); assert_perror (err); } weak_alias (__cthread_detach, cthread_detach) @@ -40,7 +41,7 @@ __cthread_fork (__cthread_fn_t func, void *arg) err = __pthread_create (&thread, NULL, func, arg); assert_perror (err); - return (__cthread_t) thread; + return (__cthread_t) (uintptr_t) thread; } weak_alias (__cthread_fork, cthread_fork) -- cgit 1.4.1