[Wayland-bugs] [Bug 55535] [task] Protocol: Integer signedness
bugzilla-daemon at freedesktop.org
bugzilla-daemon at freedesktop.org
Tue Oct 2 06:18:23 PDT 2012
https://bugs.freedesktop.org/show_bug.cgi?id=55535
Kristian Høgsberg <krh at bitplanet.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |NOTABUG
--- Comment #1 from Kristian Høgsberg <krh at bitplanet.net> ---
The uint vs int args in the protocol are all carefully chosen. The choice of
uint vs int is not about which values the argument may take, but more a
consideration of what kind of operations we're going to do on it. Adding and
comparing int and uint values result in subtle overflow bugs. For example,
you'll often be doing something like x2 - x1 < width, and if width is unsigned
and x1 and x2 are signed and x2 - x1 < 0, the x2 - x1 < width comparison will
fail. In turn you often compare width to stride, so taking all this to its
natural conclusion, width and stride should be signed, although they'll never
take negative values. The fact that a variable may never be negtive is no
different to if it was always in the 10 - 20 range, and you wouldn't pick a
different type for that either.
As a rule of thumb, we only use uint for two things: bitfields and enums.
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-bugs/attachments/20121002/db9d330e/attachment-0001.html>
More information about the Wayland-bugs
mailing list