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

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

 



On 08/10/2012 07:48 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
> 
> 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@xxxxxxxxxx>
> ---
>  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@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]