Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Avoid unportable signed integer left shift in fd_us...
details: https://anonhg.NetBSD.org/src/rev/85defe620087
branches: trunk
changeset: 320372:85defe620087
user: kamil <kamil%NetBSD.org@localhost>
date: Tue Jul 03 12:17:54 2018 +0000
description:
Avoid unportable signed integer left shift in fd_used()
Detected with Kernel Undefined Behavior Sanitizer.
There were at least a single place reported, for consistency fix all the
left bit shift operations.
sys/kern/kern_descrip.c:302:26, left shift of 1 by 31 places cannot be represented in type 'int'
Reported by <Harry Pantazis>
diffstat:
sys/kern/kern_descrip.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diffs (40 lines):
diff -r 5d11cd134f29 -r 85defe620087 sys/kern/kern_descrip.c
--- a/sys/kern/kern_descrip.c Tue Jul 03 12:12:03 2018 +0000
+++ b/sys/kern/kern_descrip.c Tue Jul 03 12:17:54 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_descrip.c,v 1.231 2017/06/01 02:45:13 chs Exp $ */
+/* $NetBSD: kern_descrip.c,v 1.232 2018/07/03 12:17:54 kamil Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.231 2017/06/01 02:45:13 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.232 2018/07/03 12:17:54 kamil Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -293,17 +293,17 @@
ff = fdp->fd_dt->dt_ff[fd];
KASSERT(mutex_owned(&fdp->fd_lock));
- KASSERT((fdp->fd_lomap[off] & (1 << (fd & NDENTRYMASK))) == 0);
+ KASSERT((fdp->fd_lomap[off] & (1U << (fd & NDENTRYMASK))) == 0);
KASSERT(ff != NULL);
KASSERT(ff->ff_file == NULL);
KASSERT(!ff->ff_allocated);
ff->ff_allocated = true;
- fdp->fd_lomap[off] |= 1 << (fd & NDENTRYMASK);
+ fdp->fd_lomap[off] |= 1U << (fd & NDENTRYMASK);
if (__predict_false(fdp->fd_lomap[off] == ~0)) {
KASSERT((fdp->fd_himap[off >> NDENTRYSHIFT] &
- (1 << (off & NDENTRYMASK))) == 0);
- fdp->fd_himap[off >> NDENTRYSHIFT] |= 1 << (off & NDENTRYMASK);
+ (1U << (off & NDENTRYMASK))) == 0);
+ fdp->fd_himap[off >> NDENTRYSHIFT] |= 1U << (off & NDENTRYMASK);
}
if ((int)fd > fdp->fd_lastfile) {
Home |
Main Index |
Thread Index |
Old Index