[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] libxc/pm: Fix NULL pointer checks.
Ian Campbell writes ("Re: [Xen-devel] [PATCH] libxc/pm: Fix NULL pointer checks."): > On Tue, 2013-09-10 at 13:23 +0100, Jan Beulich wrote: > > I'm very surprised the compiler didn't reject this - I'm unaware of > > an extension that would allow pointers to be compared by other > > than == and != (plus it's all but clear what e.g. a "negative" > > pointer really is). It is legal to compare for inequality[1] pointers into the same object. However, it is not legal to compare for inequality any null pointer; doing so is undefined behaviour. C99 6.5.8(5). > We were just discussing this at lunch and couldn't work it out either, > but indeed both gcc 4.7.[23] and clang 3.2 accept this when building > with -Wall: > int main(int argc, char **argv) > { > if ( argv[1] < 0 ) > printf("ARGV[1] < 0\n"); > else > printf("ARGV[1] >= 0\n"); > return 0; I think it would be legal for this program to be compiled into #!/bin/sh echo hahahah In the future, I wouldn't be surprised if a compiler were to maliciously optimise away the test and one of the arms, or perhaps the whole of the function. Ian. [1] < > <= >= are inequalities. == and != are not. _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |