[PATCH 1/9] render: warning fixes

Adam Jackson ajax at redhat.com
Tue Oct 19 10:58:56 PDT 2010


On Tue, 2010-10-19 at 09:15 -0700, Keith Packard wrote:
> >      /* protect against bad nglyphs */
> > -    if (gi < stuff || gi > ((CARD32 *)stuff + client->req_len) ||
> > -        bits < stuff || bits > ((CARD32 *)stuff + client->req_len)) {
> > +    if ((void *)gi < (void *)stuff ||
> > +	(void *)gi > (void *)((CARD32 *)stuff + client->req_len) ||
> > +        (void *)bits < (void *)stuff ||
> > +	(void *)bits > (void *)((CARD32 *)stuff + client->req_len)) {
> 
> I'm not entirely sure if (void *) is an ordered pointer type, or if we
> should be casting these to (char *) instead?

3.3.8 Relational operators

Syntax

          relational-expression:
                  shift-expression
                  relational-expression <   shift-expression
                  relational-expression >   shift-expression
                  relational-expression <=  shift-expression
                  relational-expression >=  shift-expression

Constraints

   One of the following shall hold: 

 * both operands have arithmetic type; 

 * both operands are pointers to qualified or unqualified versions of
   compatible object types; or

 * both operands are pointers to qualified or unqualified versions of
   compatible incomplete types.

Semantics

   If both of the operands have arithmetic type, the usual arithmetic
conversions are performed.

   When two pointers are compared, the result depends on the relative
locations in the address space of the objects pointed to.  If the
objects pointed to are members of the same aggregate object, pointers
to structure members declared later compare higher than pointers to
members declared earlier in the structure, and pointers to array
elements with larger subscript values compare higher than pointers to
elements of the same array with lower subscript values.  All pointers
to members of the same union object compare equal.  If the objects
pointed to are not members of the same aggregate or union object, the
result is undefined, with the following exception.  If P points to the
last member of an array object and Q points to a member of the same
array object, the pointer expression P+1 compares higher than Q , even
though P+1 does not point to a member of the array object.

   Each of the operators < (less than), > (greater than), <= (less
than or equal to), and >= (greater than or equal to) shall yield 1 if
the specified relation is true and 0 if it is false./38/ The result
has type int.

--- Draft ANSI C standard (ANSI X3J11/88-090),
    http://flash-gordon.me.uk/ansi.c.txt

I read this as saying that comparison between void * is legal since they
have compatible types, and does the expected thing as long as you
haven't coerced the object across address spaces.

- ajax
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.x.org/archives/xorg-devel/attachments/20101019/d9df8103/attachment.pgp>


More information about the xorg-devel mailing list