From 65a787026dbeb71f97f0857cb871823717991dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 27 Sep 2023 17:36:05 +0200 Subject: [PATCH] Fix a range check and array size. In reality, probably not a danger. --- Core/ControlMapper.cpp | 5 +++-- Core/ControlMapper.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Core/ControlMapper.cpp b/Core/ControlMapper.cpp index 5fd5c50ee0..b27a619cfa 100644 --- a/Core/ControlMapper.cpp +++ b/Core/ControlMapper.cpp @@ -480,8 +480,9 @@ void ControlMapper::Axis(const AxisInput &axis) { double now = time_now_d(); std::lock_guard guard(mutex_); - if (axis.deviceId < DEVICE_ID_COUNT) { - deviceTimestamps_[(int)axis.deviceId] = now; + size_t deviceIndex = (size_t)axis.deviceId; // this'll wrap around ANY (-1) to max, which will eliminate it on the next line, if such an event appears by mistake. + if (deviceIndex < (size_t)DEVICE_ID_COUNT) { + deviceTimestamps_[deviceIndex] = now; } if (axis.value >= 0.0f) { InputMapping mapping(axis.deviceId, axis.axisId, 1); diff --git a/Core/ControlMapper.h b/Core/ControlMapper.h index c90ae68dae..c2d6c4cd16 100644 --- a/Core/ControlMapper.h +++ b/Core/ControlMapper.h @@ -62,7 +62,7 @@ private: float virtKeys_[VIRTKEY_COUNT]{}; bool virtKeyOn_[VIRTKEY_COUNT]{}; // Track boolean output separaately since thresholds may differ. - double deviceTimestamps_[42]{}; + double deviceTimestamps_[(size_t)DEVICE_ID_COUNT]{}; int lastNonDeadzoneDeviceID_[2]{};