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> --- mach/devstream.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'mach') diff --git a/mach/devstream.c b/mach/devstream.c index 09272d1..cfa9a4f 100644 --- a/mach/devstream.c +++ b/mach/devstream.c @@ -28,7 +28,7 @@ static ssize_t devstream_write (void *cookie, const char *buffer, size_t n) { - const device_t dev = (device_t) cookie; + const device_t dev = (device_t) (uintptr_t) cookie; int write_some (const char *p, size_t to_write) { @@ -83,7 +83,7 @@ devstream_write (void *cookie, const char *buffer, size_t n) static ssize_t devstream_read (void *cookie, char *buffer, size_t to_read) { - const device_t dev = (device_t) cookie; + const device_t dev = (device_t) (uintptr_t) cookie; kern_return_t err; mach_msg_type_number_t nread = to_read; @@ -112,7 +112,8 @@ devstream_read (void *cookie, char *buffer, size_t to_read) static int dealloc_ref (void *cookie) { - if (__mach_port_deallocate (mach_task_self (), (mach_port_t) cookie)) + const device_t dev = (device_t) (uintptr_t) cookie; + if (__mach_port_deallocate (mach_task_self (), dev)) { errno = EINVAL; return -1; @@ -131,7 +132,7 @@ mach_open_devstream (mach_port_t dev, const char *mode) return NULL; } - stream = _IO_fopencookie ((void *) dev, mode, + stream = _IO_fopencookie ((void *) (uintptr_t) dev, mode, (cookie_io_functions_t) { write: devstream_write, read: devstream_read, close: dealloc_ref }); -- cgit v1.1