mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-01 22:30:42 -07:00
api: fix unbounded access in getting analog state (#544)
## Link to GitHub Issue, if one exists #0 ## Description of change Occasionally we would read a bad "vKey" for an analog axis and end up accessing invalid memory (beyond the size of a vector) and potentially crash or read junk values. ## Testing Fixed based on minidump, this was a rare repro though.
This commit is contained in:
@@ -644,11 +644,13 @@ float GameAPI::Analogs::getState(rawinput::Device *device, Analog &analog) {
|
||||
case rawinput::HID: {
|
||||
|
||||
// get value
|
||||
if (index < device->hidInfo->value_states.size()) {
|
||||
if (inverted) {
|
||||
value = 1.f - device->hidInfo->value_states[index];
|
||||
} else {
|
||||
value = device->hidInfo->value_states[index];
|
||||
}
|
||||
}
|
||||
|
||||
// deadzone
|
||||
if (analog.isDeadzoneSet()) {
|
||||
|
||||
@@ -1743,6 +1743,7 @@ namespace overlay::windows {
|
||||
auto analog_name = analog.getName();
|
||||
auto analog_display = analog.getDisplayString(RI_MGR.get());
|
||||
auto analog_state = GameAPI::Analogs::getState(RI_MGR, analog);
|
||||
analog_state = std::clamp(analog_state, 0.f, 1.f);
|
||||
|
||||
// list entry
|
||||
ImGui::ProgressBar(analog_state, ImVec2(32.f, 0));
|
||||
|
||||
Reference in New Issue
Block a user