diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-01-20 11:06:58 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-01-20 11:06:58 +0000 |
commit | 98943ee34d2f05739f515a6be453e3a44302cf39 (patch) | |
tree | 97e496e5c838fc8685dba089b7766742e6aa274d /sys/kern | |
parent | cbb735574d7946893169dfa3a86aa2e6d4792411 (diff) |
Shifting signed integers left by 31 is undefined behavior in C.
found by kubsan; joint work with tobhe@; OK miod@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_descrip.c | 12 | ||||
-rw-r--r-- | sys/kern/kern_sched.c | 12 | ||||
-rw-r--r-- | sys/kern/subr_pool.c | 4 |
3 files changed, 14 insertions, 14 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 17d9deaf54d..fe98eb87843 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.204 2021/10/25 10:24:54 claudio Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.205 2022/01/20 11:06:57 bluhm Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -156,7 +156,7 @@ fd_inuse(struct filedesc *fdp, int fd) { u_int off = fd >> NDENTRYSHIFT; - if (fdp->fd_lomap[off] & (1 << (fd & NDENTRYMASK))) + if (fdp->fd_lomap[off] & (1U << (fd & NDENTRYMASK))) return 1; return 0; @@ -167,9 +167,9 @@ fd_used(struct filedesc *fdp, int fd) { u_int off = fd >> NDENTRYSHIFT; - fdp->fd_lomap[off] |= 1 << (fd & NDENTRYMASK); + fdp->fd_lomap[off] |= 1U << (fd & NDENTRYMASK); if (fdp->fd_lomap[off] == ~0) - fdp->fd_himap[off >> NDENTRYSHIFT] |= 1 << (off & NDENTRYMASK); + fdp->fd_himap[off >> NDENTRYSHIFT] |= 1U << (off & NDENTRYMASK); if (fd > fdp->fd_lastfile) fdp->fd_lastfile = fd; @@ -185,8 +185,8 @@ fd_unused(struct filedesc *fdp, int fd) fdp->fd_freefile = fd; if (fdp->fd_lomap[off] == ~0) - fdp->fd_himap[off >> NDENTRYSHIFT] &= ~(1 << (off & NDENTRYMASK)); - fdp->fd_lomap[off] &= ~(1 << (fd & NDENTRYMASK)); + fdp->fd_himap[off >> NDENTRYSHIFT] &= ~(1U << (off & NDENTRYMASK)); + fdp->fd_lomap[off] &= ~(1U << (fd & NDENTRYMASK)); #ifdef DIAGNOSTIC if (fd > fdp->fd_lastfile) diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 6f8bf76c084..06e4bfde38f 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sched.c,v 1.73 2021/09/09 18:41:39 mpi Exp $ */ +/* $OpenBSD: kern_sched.c,v 1.74 2022/01/20 11:06:57 bluhm Exp $ */ /* * Copyright (c) 2007, 2008 Artur Grabowski <art@openbsd.org> * @@ -262,7 +262,7 @@ setrunqueue(struct cpu_info *ci, struct proc *p, uint8_t prio) p->p_p->ps_pid); TAILQ_INSERT_TAIL(&spc->spc_qs[queue], p, p_runq); - spc->spc_whichqs |= (1 << queue); + spc->spc_whichqs |= (1U << queue); cpuset_add(&sched_queued_cpus, p->p_cpu); if (cpuset_isset(&sched_idle_cpus, p->p_cpu)) @@ -286,7 +286,7 @@ remrunqueue(struct proc *p) TAILQ_REMOVE(&spc->spc_qs[queue], p, p_runq); if (TAILQ_EMPTY(&spc->spc_qs[queue])) { - spc->spc_whichqs &= ~(1 << queue); + spc->spc_whichqs &= ~(1U << queue); if (spc->spc_whichqs == 0) cpuset_del(&sched_queued_cpus, p->p_cpu); } @@ -757,21 +757,21 @@ void cpuset_add(struct cpuset *cs, struct cpu_info *ci) { unsigned int num = CPU_INFO_UNIT(ci); - atomic_setbits_int(&cs->cs_set[num/32], (1 << (num % 32))); + atomic_setbits_int(&cs->cs_set[num/32], (1U << (num % 32))); } void cpuset_del(struct cpuset *cs, struct cpu_info *ci) { unsigned int num = CPU_INFO_UNIT(ci); - atomic_clearbits_int(&cs->cs_set[num/32], (1 << (num % 32))); + atomic_clearbits_int(&cs->cs_set[num/32], (1U << (num % 32))); } int cpuset_isset(struct cpuset *cs, struct cpu_info *ci) { unsigned int num = CPU_INFO_UNIT(ci); - return (cs->cs_set[num/32] & (1 << (num % 32))); + return (cs->cs_set[num/32] & (1U << (num % 32))); } void diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index 05768b71874..744f4e1ca64 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.234 2021/06/15 05:24:46 dlg Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.235 2022/01/20 11:06:57 bluhm Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -961,7 +961,7 @@ pool_p_alloc(struct pool *pp, int flags, int *slowdown) order = arc4random(); o = 0; } - if (ISSET(order, 1 << o++)) + if (ISSET(order, 1U << o++)) XSIMPLEQ_INSERT_TAIL(&ph->ph_items, pi, pi_list); else XSIMPLEQ_INSERT_HEAD(&ph->ph_items, pi, pi_list); |