RC_Channels: zero all channels before populating

Fix for CID 308365
This commit is contained in:
Peter Barker 2018-08-07 07:52:19 +10:00 committed by Andrew Tridgell
parent ea203520fa
commit 996278e5b6
1 changed files with 3 additions and 6 deletions

View File

@ -137,16 +137,13 @@ uint16_t RC_Channels::get_radio_in(const uint8_t chan)
uint8_t RC_Channels::get_radio_in(uint16_t *chans, const uint8_t num_channels)
{
uint8_t read_channels = MIN(num_channels, NUM_RC_CHANNELS);
memset(chans, 0, num_channels*sizeof(*chans));
const uint8_t read_channels = MIN(num_channels, NUM_RC_CHANNELS);
for (uint8_t i = 0; i < read_channels; i++) {
chans[i] = channels[i].get_radio_in();
}
// clear any excess channels we couldn't read
if (read_channels < num_channels) {
memset(&chans[NUM_RC_CHANNELS], 0, sizeof(uint16_t) * (num_channels - read_channels));
}
return read_channels;
}