Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Dec 2019 06:08:29 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r356049 - head/sys/kern
Message-ID:  <201912240608.xBO68Tho073311@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Tue Dec 24 06:08:29 2019
New Revision: 356049
URL: https://svnweb.freebsd.org/changeset/base/356049

Log:
  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

Modified:
  head/sys/kern/kern_synch.c

Modified: head/sys/kern/kern_synch.c
==============================================================================
--- head/sys/kern/kern_synch.c	Tue Dec 24 01:47:08 2019	(r356048)
+++ head/sys/kern/kern_synch.c	Tue Dec 24 06:08:29 2019	(r356049)
@@ -77,7 +77,7 @@ SYSINIT(synch_setup, SI_SUB_KICK_SCHEDULER, SI_ORDER_F
     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 prio
 
 	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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912240608.xBO68Tho073311>