From af89e291b744c03697275ff081b36fc9679efe95 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 11 Sep 2022 18:23:38 +0300 Subject: [PATCH] fix: do not crash on invalid button number events, warn and continue fixes bug report #27 --- src/ui.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ui.cc b/src/ui.cc index a8c4499..a979fdf 100644 --- a/src/ui.cc +++ b/src/ui.cc @@ -308,6 +308,7 @@ void MainWin::updateui() void MainWin::spnav_input() { + static int warned_unexp_bnum; static unsigned char bnstate[MAX_BUTTONS]; static int maxval = 256; char bnstr[MAX_BUTTONS * 4 + 20]; @@ -331,6 +332,17 @@ void MainWin::spnav_input() break; case SPNAV_EVENT_RAWBUTTON: + if(ev.button.bnum >= bnrow_count) { + if(!warned_unexp_bnum) { + warned_unexp_bnum = 1; + errorboxf("Received button %d event on a %d button device.\n" + "This is a bug. Please report it:\n" + "https://github.com/FreeSpacenav/spnavcfg/issues\n" + "This warning will only be shown once.", + ev.button.bnum, bnrow_count); + } + break; + } assert(ev.button.bnum < bnrow_count); lb = bnrow[ev.button.bnum].lb_bidx;