[hurd, commited] hurd: clamp the setpriority prio argument to the range [-NZERO, NZERO-1]

Samuel Thibault <[email protected]>
Newsgroups gmane.os.hurd.cvs,gmane.comp.lib.glibc.alpha
Message-ID <[email protected]>
From: Diego Nieto Cid <[email protected]>

The Open Group Base Specifications Issue 8
getpriority ( https://pubs.opengroup.org/onlinepubs/9799919799/ )

<< The nice value is in the range [0,2*{NZERO} -1], while the
   return value for getpriority() and the third parameter for
   setpriority() are in the range [-{NZERO},{NZERO} -1]. >>

So given that NZERO is defined to 20, we shall use it to clamp to the range
specified by POSIX.

That range is then mapped to something similar to [0, 2*{NZERO}-1], as
specified by POSIX, through the usage of the macro NICE_TO_MACH_PRIORITY
and MACH_PRIORITY_TO_NICE. (i.e. [5, 45] )
---
 sysdeps/mach/hurd/setpriority.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/mach/hurd/setpriority.c b/sysdeps/mach/hurd/setpriority.c
index 23d678bf40..8107098991 100644
--- a/sysdeps/mach/hurd/setpriority.c
+++ b/sysdeps/mach/hurd/setpriority.c
@@ -28,7 +28,7 @@ __setpriority (enum __priority_which which, id_t who, int prio)
   error_t pidloser, priloser;
   unsigned int npids, ntasks, nwin, nperm, nacces;
 
-  prio = MAX (0, MIN (2 * NZERO - 1, prio));
+  prio = MAX ((-NZERO), MIN ((NZERO - 1), prio));
 
   error_t setonepriority (pid_t pid, struct procinfo *pi)
     {
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.