diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-05-19 20:11:06 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-05-19 20:11:06 +0000 |
commit | 8e20367446cbb063ea75575c99f3fbd48ea6b75b (patch) | |
tree | b214ff0f0cd1284772e334f08b126abbeace6e00 | |
parent | cfa056700cd5ccf9c5295853b2543e1e99514d29 (diff) |
Make sure our return value is withing the range 20 - -20 (aka NZERO - -NZERO).
We could use an extra call to getpriority() instead but it's faster to
just do the bounds check in userland.
-rw-r--r-- | lib/libc/gen/nice.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/libc/gen/nice.c b/lib/libc/gen/nice.c index 6c312a1da29..90537a30c31 100644 --- a/lib/libc/gen/nice.c +++ b/lib/libc/gen/nice.c @@ -32,21 +32,21 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: nice.c,v 1.4 2002/06/03 22:32:04 millert Exp $"; +static const char rcsid[] = "$OpenBSD: nice.c,v 1.5 2003/05/19 20:11:05 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> #include <errno.h> +#include <limits.h> #include <unistd.h> /* * Backwards compatible nice(). */ int -nice(incr) - int incr; +nice(int incr) { int prio; @@ -57,5 +57,6 @@ nice(incr) prio += incr; if (setpriority(PRIO_PROCESS, 0, prio) != 0) return (-1); - return (prio); + /* Valid range for prio is -NZERO to NZERO (inclusive). */ + return (prio < -NZERO ? -NZERO : prio > NZERO ? NZERO : prio); } |