AP_BattMonitor: Limit the scope of possible corruption if the NeoDesigns gets a bad cell count

This commit is contained in:
Michael du Breuil 2021-02-02 20:32:45 -07:00 committed by Andrew Tridgell
parent 699e61da57
commit f854477efe
2 changed files with 3 additions and 1 deletions

View File

@ -24,7 +24,7 @@ void AP_BattMonitor_SMBus_NeoDesign::timer()
// Get the cell count once, it's not likely to change in flight
if (_cell_count == 0) {
if (read_word(BATTMONITOR_ND_CELL_COUNT, data)) {
_cell_count = data;
_cell_count = MIN(data, max_cell_count); // never read in more cells then we can store
} else {
return; // something wrong, don't try anything else
}

View File

@ -15,4 +15,6 @@ private:
void timer(void) override;
uint8_t _cell_count;
static const constexpr uint8_t max_cell_count = 10;
};