Bug 83295

Summary: difference of non negative enums is never negative
Product: cairo Reporter: Massimo <sixtysix>
Component: generalAssignee: Chris Wilson <chris>
Status: RESOLVED MOVED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Massimo 2014-08-31 13:53:41 UTC
Gcc treats enum with non negative values as unsigned,
so using the difference in a comparison function is
questionable:

http://cgit.freedesktop.org/cairo/tree/src/cairo-polygon-intersect.c#n794

for example adding a 

assert (a->type - b->type >= 0);

gcc prints

src/cairo-polygon-intersect.c|795 col 15| warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
      assert (a->type - b->type >= 0);

this means that three events (START, STOP, INTERSECTION) in the same
place will be potentially each one after each other, making difficult
to understand whether equally located STOP/INTER/START events should be
really processed in that order or not.
Comment 1 Chris Wilson 2014-08-31 14:00:21 UTC
But that is not equivalent. The equivalent assert would be assert((int)(a->type - b->type) >= 0);
Comment 2 Massimo 2014-08-31 14:22:22 UTC
(In reply to comment #1)
> But that is not equivalent. The equivalent assert would be
> assert((int)(a->type - b->type) >= 0);

but that means that you are assigning/converting UINT_MAX - 1 or 2
to an int and gcc knows it cannot happen and I think after 
inlining and only checking the sign of the int gcc translates it
to a->type != b->type
Comment 3 GitLab Migration User 2018-08-25 13:36:56 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/98.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.