Fix index underflow causing segfault on DPI change (#241)

* Fix index underflow causing segfault on DPI change

* Stop over-allocating sensor lists
This commit is contained in:
Naman Sood 2021-05-08 18:06:17 -04:00 committed by GitHub
parent 990f923e7a
commit 7b297fc49f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,9 +103,10 @@ void DPI::setDPI(uint16_t dpi, uint8_t sensor)
hidpp20::AdjustableDPI::SensorDPIList dpi_list;
if(_dpi_lists.size() <= sensor) {
dpi_list = _adjustable_dpi->getSensorDPIList(sensor);
for(std::size_t i = _dpi_lists.size()-1; i <= sensor; i++) {
for(std::size_t i = _dpi_lists.size(); i < sensor; i++) {
_dpi_lists.push_back(_adjustable_dpi->getSensorDPIList(i));
}
_dpi_lists.push_back(dpi_list);
}
dpi_list = _dpi_lists[sensor];
_adjustable_dpi->setSensorDPI(sensor, getClosestDPI(dpi_list, dpi));