summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2014-05-22 10:43:52 +1200
committerPeter Hutterer <peter.hutterer@who-t.net>2014-05-23 14:38:59 +1000
commit548fc937b22d4dfe7f96e0bd77522261603a2c2f (patch)
treee9e1be99fd45538f9956bb79a0f4a8d3578dff97
parentd7a2df0a7499864cb005b098b79c1bdf884f6600 (diff)
Fix overflow checking extension versions
The easiest way to check for the version of an extension is to send the maximum possible version numbers in the QueryVersion request. The X server overflows on these as it assumes you will send a reasonable version number. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Keith Packard <keithp@keithp.com>
-rw-r--r--include/misc.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/include/misc.h b/include/misc.h
index 17de71041..9c2f573b9 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -259,15 +259,19 @@ extern void FormatDouble(double dbl, char *string);
* or a value greater than 0
*/
static inline int
-version_compare(uint16_t a_major, uint16_t a_minor,
- uint16_t b_major, uint16_t b_minor)
+version_compare(uint32_t a_major, uint32_t a_minor,
+ uint32_t b_major, uint32_t b_minor)
{
- int a, b;
+ if (a_major > b_major)
+ return 1;
+ if (a_major < b_major)
+ return -1;
+ if (a_minor > b_minor)
+ return 1;
+ if (a_minor < b_minor)
+ return -1;
- a = a_major << 16 | a_minor;
- b = b_major << 16 | b_minor;
-
- return (a - b);
+ return 0;
}
/* some macros to help swap requests, replies, and events */