[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 Fri, Aug 10, 2012 at 03:02:24PM -0600, Eric Blake wrote:
> 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?

Ok, changed this.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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