vintlabs / fauxmoESP

Add voice control of your ESP32 and ESP8266 devices using Amazon Alexa
MIT License
389 stars 71 forks source link

Bad indexes #56

Closed pvint closed 5 years ago

pvint commented 6 years ago

Original report by Paul Andrews (Bitbucket: [Paul Andrews](https://bitbucket.org/Paul Andrews), ).


There are several places with statements like this:

if (0 <= id && id <= _devices.size()) {

an id that is equal to _devices.size() would be out of range - for example, if there is one element in _devices, _devices.size() would be 1. _devices[1] would be out of range.

Also because id is unsigned, it is by definition >= 0, so the first test is not necessary. The entire statement should be:

if (id < _devices.size()) {
pvint commented 5 years ago

Original comment by Xose Pérez (Bitbucket: [Xose Pérez](https://bitbucket.org/Xose Pérez), ).


Fixed. Thank you!