From 1ec01b13104ad8feb35c21483cf2e79140a75604 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Jan 2017 14:42:48 +1000 Subject: [PATCH] tools: print an error if we don't have any matching events in the dpi tool Beats crashing by dereferencing a null-pointer (when we access m->frequencies[idx]) Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires --- tools/mouse-dpi-tool.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/mouse-dpi-tool.c b/tools/mouse-dpi-tool.c index 13cefbc..b472ad0 100644 --- a/tools/mouse-dpi-tool.c +++ b/tools/mouse-dpi-tool.c @@ -215,8 +215,15 @@ static void print_summary(struct libevdev *dev, struct measurements *m) { int res; - int max_freq = (int)m->max_frequency, - mean_freq = (int)mean_frequency(m); + int max_freq, mean_freq; + + if (m->nfrequencies == 0) { + fprintf(stderr, "Error: no matching events received.\n"); + return; + } + + max_freq = (int)m->max_frequency; + mean_freq = (int)mean_frequency(m); printf("Estimated sampling frequency: %dHz (mean %dHz)\n", max_freq, mean_freq); -- 2.34.1