mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 00:35:18 +03:00
Out of bounds protection for telemetryItems[] array access and some code refactoring for telemetry value precision
This commit is contained in:
parent
4ef9913f76
commit
082ba0893d
8 changed files with 49 additions and 28 deletions
|
@ -366,10 +366,7 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
|
|||
result += dist*dist;
|
||||
|
||||
if (altItem) {
|
||||
dist = abs(altItem->value);
|
||||
uint8_t prec = g_model.telemetrySensors[sensor.dist.alt-1].prec;
|
||||
if (prec > 0)
|
||||
dist /= (prec==2 ? 100 : 10);
|
||||
dist = abs(altItem->value) / g_model.telemetrySensors[sensor.dist.alt-1].getPrecDivisor();
|
||||
result += dist*dist;
|
||||
}
|
||||
|
||||
|
@ -545,7 +542,7 @@ void TelemetrySensor::init(uint16_t id)
|
|||
init(label);
|
||||
}
|
||||
|
||||
bool TelemetrySensor::isAvailable()
|
||||
bool TelemetrySensor::isAvailable() const
|
||||
{
|
||||
return ZLEN(label) > 0;
|
||||
}
|
||||
|
@ -622,7 +619,7 @@ int32_t TelemetrySensor::getValue(int32_t value, uint8_t unit, uint8_t prec) con
|
|||
return value;
|
||||
}
|
||||
|
||||
bool TelemetrySensor::isConfigurable()
|
||||
bool TelemetrySensor::isConfigurable() const
|
||||
{
|
||||
if (type == TELEM_TYPE_CALCULATED) {
|
||||
if (formula >= TELEM_FORMULA_CELL) {
|
||||
|
@ -637,7 +634,7 @@ bool TelemetrySensor::isConfigurable()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool TelemetrySensor::isPrecConfigurable()
|
||||
bool TelemetrySensor::isPrecConfigurable() const
|
||||
{
|
||||
if (isConfigurable()) {
|
||||
return true;
|
||||
|
@ -649,3 +646,17 @@ bool TelemetrySensor::isPrecConfigurable()
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t TelemetrySensor::getPrecMultiplier() const
|
||||
{
|
||||
if (prec == 2) return 1;
|
||||
if (prec == 1) return 10;
|
||||
return 100;
|
||||
}
|
||||
|
||||
uint32_t TelemetrySensor::getPrecDivisor() const
|
||||
{
|
||||
if (prec == 2) return 100;
|
||||
if (prec == 1) return 10;
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue