tools: print an error if we don't have any matching events in the dpi tool
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 17 Jan 2017 04:42:48 +0000 (14:42 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 17 Jan 2017 04:50:29 +0000 (14:50 +1000)
Beats crashing by dereferencing a null-pointer (when we access
m->frequencies[idx])

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
tools/mouse-dpi-tool.c

index 13cefbc879528993bba9a6b40928cfac6ce6907c..b472ad02d281ef01db2b151d8c28d4584ea40941 100644 (file)
@@ -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);