Subject: Re: commoning up code that changes uids and gids
To: Luke Mewburn <lukem@netbsd.org>
From: Jaromir Dolecek <jdolecek@netbsd.org>
List: tech-kern
Date: 03/27/2003 19:39:47
Luke Mewburn wrote:
> On Sun, Mar 09, 2003 at 07:19:29PM +0000, David Laight wrote:
>   | > Also, you didn't adress the issue I raised - that ruid
>   | > in sys_setreuid() is always set to as 'p->p_cred->p_ruid ? -1 : euid;',
>   | > so the previous 'if (ruid == -1) ruid = p->p_cred->p_ruid;' has
>   | > no effect. Other routines might have similar issues.
>   | 
>   | svuid = ruid == p->p_cred->p_ruid ? -1 : euid;
>   | 
>   | Is an assignment to svuid, not ruid.
> 
> Seeing as this did cause more confusion that it's worth, could you
> just add a couple of parenthesis.  E.g;
> 	svuid = (ruid == p->p_cred->p_ruid ? -1 : euid);
> or
> 	svuid = (ruid == p->p_cred->p_ruid) ? -1 : euid;

Ouch, thanks Luke for pointing out the obvious. I thought there
is single '=' there ...
I've committed change to use the latter form (var = (check) ? x : y)
in there.

Thanks,

Jaromir 
> 
> [Per /usr/share/misc/style:
> 	* Don't excessively use parenthesis, but they should be used if
> 	* statement is really confusing without them [...]
> Your existing code did cause confusion.  I had to read Jaromir's query
> a couple of times to double check that you were doing the right thing;
> had the parens been there it would have been much more obvious :]
> 


-- 
Jaromir Dolecek <jdolecek@NetBSD.org>            http://www.NetBSD.org/
-=- We should be mindful of the potential goal, but as the tantric    -=-
-=- Buddhist masters say, ``You may notice during meditation that you -=-
-=- sometimes levitate or glow.   Do not let this distract you.''     -=-