Out of bounds protection for telemetryItems[] array access and some code refactoring for telemetry value precision
This commit is contained in:
@@ -236,22 +236,26 @@ void displayTopBar()
|
||||
/* Rx voltage */
|
||||
altitude_icon_x = batt_icon_x+7*FW+3;
|
||||
if (g_model.frsky.voltsSource) {
|
||||
TelemetryItem & voltsItem = telemetryItems[g_model.frsky.voltsSource-1];
|
||||
if (voltsItem.isAvailable()) {
|
||||
putsTelemetryChannelValue(batt_icon_x+7*FW+2, BAR_Y+1, g_model.frsky.voltsSource-1, voltsItem.value, LEFT);
|
||||
altitude_icon_x = lcdLastPos+1;
|
||||
uint8_t item = g_model.frsky.voltsSource-1;
|
||||
if (item < MAX_SENSORS) {
|
||||
TelemetryItem & voltsItem = telemetryItems[item];
|
||||
if (voltsItem.isAvailable()) {
|
||||
putsTelemetryChannelValue(batt_icon_x+7*FW+2, BAR_Y+1, item, voltsItem.value, LEFT);
|
||||
altitude_icon_x = lcdLastPos+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Altitude */
|
||||
if (g_model.frsky.altitudeSource) {
|
||||
TelemetryItem & altitudeItem = telemetryItems[g_model.frsky.altitudeSource-1];
|
||||
if (altitudeItem.isAvailable()) {
|
||||
LCD_ICON(altitude_icon_x, BAR_Y, ICON_ALTITUDE);
|
||||
int32_t value = altitudeItem.value;
|
||||
TelemetrySensor & sensor = g_model.telemetrySensors[g_model.frsky.altitudeSource-1];
|
||||
if (sensor.prec) value /= sensor.prec == 2 ? 100 : 10;
|
||||
putsValueWithUnit(altitude_icon_x+2*FW-1, BAR_Y+1, value, UNIT_METERS, LEFT);
|
||||
uint8_t item = g_model.frsky.altitudeSource-1;
|
||||
if (item < MAX_SENSORS) {
|
||||
TelemetryItem & altitudeItem = telemetryItems[item];
|
||||
if (altitudeItem.isAvailable()) {
|
||||
LCD_ICON(altitude_icon_x, BAR_Y, ICON_ALTITUDE);
|
||||
int32_t value = altitudeItem.value / g_model.telemetrySensors[item].getPrecDivisor();
|
||||
putsValueWithUnit(altitude_icon_x+2*FW-1, BAR_Y+1, value, UNIT_METERS, LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user