xlib plugin: relax button value assertions
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 4 Jul 2022 21:44:42 +0000 (14:44 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 9 Jul 2022 05:13:00 +0000 (22:13 -0700)
Contrary to the X11 documentation,¹ it seems button values other than 1-5 can be
returned as button press events. The assertions altered in this commit were
introduced to guarantee the value does not exceed the limits of the type of the
parameter in the user’s callback (`int`). So we can safely relax this to just
the limit itself.

Gitlab: fixes #2256

¹ https://www.x.org/releases/X11R7.7/doc/libX11/libX11/libX11.html#Keyboard_and_Pointer_Events_b

CHANGELOG.md
plugin/xlib/gvdevice_xlib.c

index 21c0b77a88f542bf38daa78669c5016c530dc893..63c5d145d373ffd5ea8c3dac9d357ba228ff899b 100644 (file)
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased (5.0.1)]
 
+### Fixed
+
+- -Tx11: Assertion `xev.xbutton.button >= 1 && xev.xbutton.button <= 5 && "Xlib
+  returned invalid button event"` failed #2256
+
 ## [5.0.0] – 2022-07-07
 
 ### Changed
index db903bfc812d94d4545e971143c19a60ecae7127..05cfbed334344161b5cc9600e971caadacf020bd 100644 (file)
@@ -188,7 +188,7 @@ static int handle_xlib_events (GVJ_t *firstjob, Display *dpy)
                 case ButtonPress:
                    pointer.x = (double)xev.xbutton.x;
                    pointer.y = (double)xev.xbutton.y;
-                    assert(xev.xbutton.button >= 1 && xev.xbutton.button <= 5 &&
+                    assert(xev.xbutton.button <= (unsigned)INT_MAX &&
                            "Xlib returned invalid button event");
                     job->callbacks->button_press(job, (int)xev.xbutton.button,
                                                  pointer);
@@ -205,7 +205,7 @@ static int handle_xlib_events (GVJ_t *firstjob, Display *dpy)
                 case ButtonRelease:
                    pointer.x = (double)xev.xbutton.x;
                    pointer.y = (double)xev.xbutton.y;
-                    assert(xev.xbutton.button >= 1 && xev.xbutton.button <= 5 &&
+                    assert(xev.xbutton.button <= (unsigned)INT_MAX &&
                            "Xlib returned invalid button event");
                     job->callbacks->button_release(job, (int)xev.xbutton.button,
                                                    pointer);