bolderflight / sbus

Arduino and CMake library for communicating with SBUS receivers and servos.
MIT License
397 stars 141 forks source link

Possible failure in parse function #36

Closed alejandrosr98 closed 4 years ago

alejandrosr98 commented 4 years ago

In the following code, when the end byte is checked, no byte is read. The first if is verified with the last information byte, and the second if is immediately verified without read any byte. Therefore, if the last byte doesn't match with the end byte, the parse function will return false and the read will fail

// strip off the data
            if ((_parserState-1) < _payloadSize) {
                _payload[_parserState-1] = _curByte;
                _parserState++;
            }
            // check the end byte
            if ((_parserState-1) == _payloadSize) {
                if ((_curByte == _sbusFooter) || ((_curByte & _sbus2Mask) == _sbus2Footer)) {
                    _parserState = 0;
                    return true;
                } else {
                    _parserState = 0;
                    return false;
                }
            }
alejandrosr98 commented 4 years ago

It's fine how is it