From e30f025ff95d3bb03b19322e8a58e781881b2166 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Tue, 24 Dec 2019 06:08:29 +0000 Subject: [PATCH] kern_synch: Fix some UB It is UB to evaluate pointer comparisons when pointers do not point within the same object. Instead, convert the pointers to numbers and compare the numbers. Reported by: kib Discussed with: rlibby --- sys/kern/kern_synch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 944a48044f6..0bb25f5f0ad 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -77,7 +77,7 @@ SYSINIT(synch_setup, SI_SUB_KICK_SCHEDULER, SI_ORDER_FIRST, synch_setup, NULL); int hogticks; -static uint8_t pause_wchan[MAXCPU]; +static char pause_wchan[MAXCPU]; static struct callout loadav_callout; @@ -169,8 +169,8 @@ _sleep(void *ident, struct lock_object *lock, int priority, KASSERT(!TD_ON_SLEEPQ(td), ("recursive sleep")); - if ((uint8_t *)ident >= &pause_wchan[0] && - (uint8_t *)ident <= &pause_wchan[MAXCPU - 1]) + if ((uintptr_t)ident >= (uintptr_t)&pause_wchan[0] && + (uintptr_t)ident <= (uintptr_t)&pause_wchan[MAXCPU - 1]) sleepq_flags = SLEEPQ_PAUSE; else sleepq_flags = SLEEPQ_SLEEP;