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
This commit is contained in:
Conrad Meyer 2019-12-24 06:08:29 +00:00
parent f3ea8d846a
commit e30f025ff9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=356049

View file

@ -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;