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: <20130530122300.GD2475@ritirata.org>
Date:	Thu, 30 May 2013 14:23:00 +0200
From:	Antonio Quartulli <ordex@...istici.org>
To:	David Laight <David.Laight@...LAB.COM>
Cc:	Ben Hutchings <bhutchings@...arflare.com>,
	David Miller <davem@...emloft.net>, amwang@...hat.com,
	netdev@...r.kernel.org, horms@...ge.net.au
Subject: Re: [Patch net-next] net: clean up skb headers code

On Thu, May 30, 2013 at 01:12:15PM +0100, David Laight wrote:
> > > > > > > I want to use something that will either break the build or
> > > > > > > automatically work if the type changes again.
> > > > > > >
> > > > > > > So something like "X = (typeof(X)) ~0U;".
> > > > > >
> > > > > > I think you mean ~(typeof(X))0.
> > > > >
> > > > > Am I wrong or you should cast the value once again, like this:
> > > > >
> > > > > ((typeof(X))~(typeof(X))0)
> > > > >
> > > > > because the ~ operator will implicitly cast the argument to int (if I remember
> > > > > correctly).
> > > >
> > > > It will promote to at least int, but that still results in the right
> > > > value and doesn't provoke a warning.  Try this test (with -Wall
> > > > -Wextra):
> > > >
> > > > #include <stdio.h>
> > > >
> > > > #define ALL_ONES(v) (~(typeof(v))0)
> > > > /* #define ALL_ONES(v) (typeof(v))~0U) */
> > > >
> > > > int main(void)
> > > > {
> > > >     char a = ALL_ONES(a);
> > > >     unsigned char b = ALL_ONES(b);
> > > >     short c = ALL_ONES(c);
> > > >     unsigned short d = ALL_ONES(d);
> > > >     int e = ALL_ONES(e);
> > > >     unsigned int f = ALL_ONES(f);
> > > >     long g = ALL_ONES(g);
> > > >     unsigned long h = ALL_ONES(h);
> > > >     long long i = ALL_ONES(i);
> > > >     unsigned long long j = ALL_ONES(j);
> > > >
> > > >     printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n",
> > > > 	   a, b, c, d, e, f, g, h, i, j);
> > > >     return 0;
> > > > }
> > >
> > > The printf format is masking the high bits for you.
> > > If you change to:
> > > 	printf("%x %x %x %x %x %x %lx %lx %llx %llx\n", ...)
> > > you get different values.
> > > To get the 'expected' values you need casts both sides of the ~
> > 
> > I tried with
> > 
> > 19     printf("%x %x %x %x %x %x %lx %lx %llx %llx\n",
> > 
> > but I still see all FF.
> > 
> > Somewhere else we have some hidden conversion?
> 
> Of course - we need to look at the value that ALL_ONES()
> generates in an expression. So the test print needs to be:
> 	printf("%hhx %hhx %hx %hx %x %x %lx %lx %llx %llx\n",
> 		ALL_ONES(a), ALL_ONES(b), ALL_ONES(c), ALL_ONES(d),
> 		ALL_ONES(e), ALL_ONES(f), ALL_ONES(g), ALL_ONES(h),
> 		ALL_ONES(i), ALL_ONES(j));
> which then gives 0xffffffff for the first 4 entries.

It gives all FF for every argument. So, I'm not understanding the problem..this
is what Ben wanted to achieve, no?

Cheers,

-- 
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara

Download attachment "signature.asc" of type "application/pgp-signature" (837 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ