From eedb74701eebeb73fe97edb62de33463f549edc5 Mon Sep 17 00:00:00 2001 From: 3405691582 Date: Wed, 7 Jul 2021 13:01:27 -0400 Subject: [PATCH] Cast when printing dispatch_unote_ident_t. Different platforms may define dispatch_unote_ident_t differently and subsequently this type may have different bit widths. Therefore, when printing du_ident, cast explicitly to deal with format mismatch errors. The alternative is to specify explicit format string macros, but this is a little complex and casting is already being used in #584. One special case for consideration is `_dispatch_timer_unote_disarm`; this gets the `du_ident` and converts that into a `uint32_t` timer index. When `dispatch_unote_ident` is a `uint32_t` this is of course fine, but needs consideration for when it isn't. Here, we just cast down. This is somewhat reasonable since this is initialized from `_dispatch_timer_unote_idx` which returns an `unsigned int`. (Of course, we are not actually bounds checking that index, but that's outside the scope of this commit). --- src/event/event.c | 4 ++-- src/event/event_internal.h | 2 ++ src/event/event_kevent.c | 4 ++-- src/init.c | 6 +++--- src/source.c | 3 +-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/event/event.c b/src/event/event.c index 6ace80ecb..f865604b1 100644 --- a/src/event/event.c +++ b/src/event/event.c @@ -768,7 +768,7 @@ _dispatch_timer_heap_update(dispatch_timer_heap_t dth, #define _dispatch_timer_du_debug(what, du) \ _dispatch_debug("kevent-source[%p]: %s kevent[%p] { ident = 0x%llx }", \ _dispatch_wref2ptr((du)->du_owner_wref), what, \ - (du), (unsigned long long)((du)->du_ident)) + (du), (unsigned long long)(du)->du_ident) DISPATCH_ALWAYS_INLINE static inline unsigned int @@ -792,7 +792,7 @@ static void _dispatch_timer_unote_disarm(dispatch_timer_source_refs_t dt, dispatch_timer_heap_t dth) { - uint32_t tidx = dt->du_ident; + uint32_t tidx = (uint32_t)dt->du_ident; dispatch_assert(_dispatch_unote_armed(dt)); _dispatch_timer_heap_remove(&dth[tidx], dt); diff --git a/src/event/event_internal.h b/src/event/event_internal.h index 14c485ee3..5b2c7fc80 100644 --- a/src/event/event_internal.h +++ b/src/event/event_internal.h @@ -125,6 +125,8 @@ _dispatch_timer_flags_from_clock(dispatch_clock_t clock) #if defined(_WIN32) typedef uintptr_t dispatch_unote_ident_t; +#elif defined(__OpenBSD__) +typedef uintptr_t dispatch_unote_ident_t; #else typedef uint32_t dispatch_unote_ident_t; #endif diff --git a/src/event/event_kevent.c b/src/event/event_kevent.c index 0e8906844..38ac50c77 100644 --- a/src/event/event_kevent.c +++ b/src/event/event_kevent.c @@ -240,9 +240,9 @@ dispatch_kevent_debug(const char *verb, const dispatch_kevent_s *kev, #define _dispatch_du_debug(what, du) \ _dispatch_debug("kevent-source[%p]: %s kevent[%p] " \ - "{ filter = %s, ident = 0x%x }", \ + "{ filter = %s, ident = 0x%llx }", \ _dispatch_wref2ptr((du)->du_owner_wref), what, \ - (du), _evfiltstr((du)->du_filter), (du)->du_ident) + (du), _evfiltstr((du)->du_filter), (unsigned long long)(du)->du_ident) #if DISPATCH_MACHPORT_DEBUG #ifndef MACH_PORT_TYPE_SPREQUEST diff --git a/src/init.c b/src/init.c index 0fe0e4385..af5c91b58 100644 --- a/src/init.c +++ b/src/init.c @@ -1049,7 +1049,7 @@ _dispatch_bug_kevent_vanished(dispatch_unote_t du) "{ %p[%s], ident: %" PRIdPTR " / 0x%" PRIxPTR ", handler: %p }", dux_type(du._du)->dst_kind, dou._dq, dou._dq->dq_label ? dou._dq->dq_label : "", - du._du->du_ident, du._du->du_ident, func); + (intptr_t)du._du->du_ident, (uintptr_t)du._du->du_ident, func); } #endif // RDAR_49023449 @@ -1154,8 +1154,8 @@ _dispatch_logv_init(void *context DISPATCH_UNUSED) } #else dprintf(dispatch_logfile, "=== log file opened for %s[%u] at " - "%ld.%06u ===\n", getprogname() ?: "", getpid(), - tv.tv_sec, (int)tv.tv_usec); + "%lld.%06u ===\n", getprogname() ?: "", getpid(), + (time_t)tv.tv_sec, (int)tv.tv_usec); #endif } } diff --git a/src/source.c b/src/source.c index d1581351d..527938d5f 100644 --- a/src/source.c +++ b/src/source.c @@ -1402,8 +1402,7 @@ _dispatch_source_debug_attr(dispatch_source_t ds, char* buf, size_t bufsiz) "mask = 0x%x, pending_data = 0x%llx, registered = %d, " "armed = %d, %s%s%s", target && target->dq_label ? target->dq_label : "", target, - (unsigned long long)dr->du_ident, dr->du_fflags, - (unsigned long long)dr->ds_pending_data, + (unsigned long long)dr->du_ident, dr->du_fflags, (unsigned long long)dr->ds_pending_data, _du_state_registered(du_state), _du_state_armed(du_state), (dqf & DSF_CANCELED) ? "cancelled, " : "", (dqf & DSF_NEEDS_EVENT) ? "needs-event, " : "",