From 9086681b0775ad92ce39df96d22ff5a3fe06c68f Mon Sep 17 00:00:00 2001 From: Mamoru TASAKA Date: Fri, 4 Mar 2022 11:24:49 +0900 Subject: [PATCH] print_xinput_event: check if XIRawEvent.raw_values is available gcc12 -sanitize=address shows that XIRawEvent.raw_values is not always available. XIRawEvent buffer is allocated on wireToRawEvent() in XExtInt.c in libXi. Follow wireToRawEvent() implementation to check is XIRawEvent.raw_values is available, using XIRawEvent.valuators.mask_len, valuators.mask and XIMaskIsSet. --- driver/xinput.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/driver/xinput.c b/driver/xinput.c index 9402a4f..2ce2ce1 100644 --- a/driver/xinput.c +++ b/driver/xinput.c @@ -296,6 +296,30 @@ print_kbd_event (XEvent *xev, XComposeStatus *compose, Bool x11_p) } } +/* see wireToRawEvent, count_bits in libXi and XIMaskIsSet in X11/extensions/XI2.h */ +static void +print_xi_raw_event_raw_values (XIRawEvent *re) +{ + int mask_pos; + double *raw_values_pos = re->raw_values; + int first_time_p; + + first_time_p = 1; + + for (mask_pos = 0; mask_pos < re->valuators.mask_len * sizeof(char); mask_pos++) + { + if (XIMaskIsSet(re->valuators.mask, mask_pos)) + { + if (first_time_p) + { + first_time_p = 0; + fprintf(stderr, " %7.02f", *raw_values_pos++); + } else { + fprintf(stderr, ", %-7.02f", *raw_values_pos++); + } + } + } +} void print_xinput_event (Display *dpy, XEvent *xev, const char *desc) @@ -371,11 +395,12 @@ print_xinput_event (Display *dpy, XEvent *xev, const char *desc) XQueryPointer (dpy, DefaultRootWindow (dpy), &root_ret, &child_ret, &root_x, &root_y, &win_x, &win_y, &mask); - fprintf (stderr, "%s: XI _RawButton%s %4d, %-4d %7.02f, %-7.02f\n", + fprintf (stderr, "%s: XI _RawButton%s %4d, %-4d", blurb(), (re->evtype == XI_RawButtonPress ? "Press " : "Release"), - root_x, root_y, - re->raw_values[0], re->raw_values[1]); + root_x, root_y); + print_xi_raw_event_raw_values(re); + fprintf(stderr, "\n"); } break; @@ -390,9 +415,10 @@ print_xinput_event (Display *dpy, XEvent *xev, const char *desc) &root_ret, &child_ret, &root_x, &root_y, &win_x, &win_y, &mask); fprintf (stderr, - "%s: XI_RawMotion %4d, %-4d %7.02f, %-7.02f%s\n", - blurb(), root_x, root_y, re->raw_values[0], re->raw_values[1], - (desc ? desc : "")); + "%s: XI_RawMotion %4d, %-4d ", + blurb(), root_x, root_y); + print_xi_raw_event_raw_values(re); + fprintf (stderr, "%s\n", (desc ? desc : "")); } break; -- 2.35.1