Avoid undefined behavior in an cpuset.c
Do not change the signedness bit with a left shift operation. Switch to unsigned integer to prevent this. cpuset.c:112:18, left shift of 1 by 31 places cannot be represented in type 'int' Detected with micro-UBSan in the user mode.
This commit is contained in:
parent
21d1b523b3
commit
4581cca75c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cpuset.c,v 1.19 2018/01/04 20:57:28 kamil Exp $ */
|
||||
/* $NetBSD: cpuset.c,v 1.20 2018/07/26 00:13:19 kamil Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
@ -32,7 +32,7 @@
|
||||
#ifndef _STANDALONE
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: cpuset.c,v 1.19 2018/01/04 20:57:28 kamil Exp $");
|
||||
__RCSID("$NetBSD: cpuset.c,v 1.20 2018/07/26 00:13:19 kamil Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#ifdef _LIBC
|
||||
@ -97,7 +97,7 @@ _cpuset_isset(cpuid_t i, const cpuset_t *c)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return ((1 << (unsigned int)(i & CPUSET_MASK)) & c->bits[j]) != 0;
|
||||
return ((1U << (unsigned int)(i & CPUSET_MASK)) & c->bits[j]) != 0;
|
||||
}
|
||||
|
||||
int
|
||||
@ -109,7 +109,7 @@ _cpuset_set(cpuid_t i, cpuset_t *c)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
c->bits[j] |= 1 << (unsigned int)(i & CPUSET_MASK);
|
||||
c->bits[j] |= 1U << (unsigned int)(i & CPUSET_MASK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ _cpuset_clr(cpuid_t i, cpuset_t *c)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
c->bits[j] &= ~(1 << (unsigned int)(i & CPUSET_MASK));
|
||||
c->bits[j] &= ~(1U << (unsigned int)(i & CPUSET_MASK));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user