[PATCH libevdev 2/2] tools: print an error if we don't have any matching events in the dpi tool
Peter Hutterer
peter.hutterer at who-t.net
Tue Jan 17 04:51:35 UTC 2017
Beats crashing by dereferencing a null-pointer (when we access
m->frequencies[idx])
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
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.9.3
More information about the Input-tools
mailing list