lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1211366932.6463.81.camel@lappy.programming.kicks-ass.net>
Date:	Wed, 21 May 2008 12:48:52 +0200
From:	Peter Zijlstra <a.p.zijlstra@...llo.nl>
To:	Peter 1 Oberparleiter <Peter.Oberparleiter@...ibm.com>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	Harvey Harrison <harvey.harrison@...il.com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] consolidate all within() implementations

On Wed, 2008-05-21 at 12:33 +0200, Peter 1 Oberparleiter wrote:
> Peter Zijlstra <a.p.zijlstra@...llo.nl> wrote on 21.05.2008 12:04:26:
> > > +static inline int addr_within_len(const void *addr, const void 
> *start,
> > > +              size_t len)
> > > +{
> > > +   return ((unsigned long) addr >= (unsigned long) start) &&
> > > +          ((unsigned long) addr < ((unsigned long) start + len));
> > > +}
> > 
> > might be my braindamage, but I'd have written it like:
> > 
> > static inline int 
> > addr_within_len(const void *addr, const void *start, size_t len)
> > {
> >    return (unsigned long)addr - (unsigned long)start < len;
> > }
> 
> Definitely another way to put it. In my opinion the intention of the
> implementation is more easily understood though when spelling it out
> as (a>=b) && (a<c).

peter@...py:~/tmp$ cat cmp.c

int within_len1(const void *addr, const void *start, unsigned long len)
{
        return (unsigned long)addr - (unsigned long)start < len;
}

int within1(const void *addr, const void *start, const void *end)
{
        return within_len1(addr, start,
                        (unsigned long)end - (unsigned long)start);
}
peter@...py:~/tmp$ cat cmp2.c
int within_len2(const void *addr, const void *start, unsigned long len)
{
        return ((unsigned long) addr >= (unsigned long) start) &&
                ((unsigned long) addr < ((unsigned long) start + len));
}

int within2(const void *addr, const void *start, const void *end)
{
        return ((unsigned long) addr >= (unsigned long) start) &&
                ((unsigned long) addr < ((unsigned long) end));
}
peter@...py:~/tmp$ gcc -S -Os cmp*.c
peter@...py:~/tmp$ ls -la cmp*.o
-rw-r--r-- 1 peter peter 752 2008-05-21 12:43 cmp2.o
-rw-r--r-- 1 peter peter 743 2008-05-21 12:43 cmp.o


Also look at the .s output and notice mine doesn't have any additional
branches ;-)

> > static inline int
> > addr_within(const void *add, const void *start, const void *end)
> > {
> >    return addr_within_len(addr, start, 
> >          (unsigned long)end - (unsigned long)start);
> > }
> 
> For empty ranges (start > end), this produces different (less expected)
> results than the previous version.

agreed, do we care about those?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ