[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 6/8] Pull code which finds a free MCS label out into its own method



On 08/10/2012 07:48 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange redhat com>
> 
> The code for picking a MCS label is about to get significantly
> more complicated, so it deserves to be in a standlone method,
> instead of a switch/case body.
> 
> Signed-off-by: Daniel P. Berrange <berrange redhat com>
> ---
>  src/security/security_selinux.c | 75 ++++++++++++++++++++++++++---------------
>  1 file changed, 47 insertions(+), 28 deletions(-)
> 

ACK.

> +
> +static char *
> +virSecuritySELinuxMCSFind(virSecurityManagerPtr mgr)
> +{
> +    virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(mgr);
> +    int c1 = 0;
> +    int c2 = 0;
> +    char *mcs = NULL;
> +
> +    for (;;) {
> +        c1 = virRandomBits(10);
> +        c2 = virRandomBits(10);
> +
> +        if (c1 == c2) {
> +            if (virAsprintf(&mcs, "s0:c%d", c1) < 0) {
> +                virReportOOMError();
> +                return NULL;
> +            }
> +        } else {
> +            if (c1 > c2) {
> +                c1 ^= c2;
> +                c2 ^= c1;
> +                c1 ^= c2;

I know this is just code motion, but is it really that hard to just
write the more straightforward:

int tmp = c1;
c1 = c2;
c2 = tmp;

which probably optimizes better in the compiler?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]