Prevent dist calculation overflow

This commit is contained in:
3djc
2019-05-19 08:17:59 +02:00
parent 1a5d62262d
commit 3528d773d2
+2 -2
View File
@@ -355,11 +355,11 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
}
}
uint32_t angle = abs(gpsItem.gps.latitude - gpsItem.pilotLatitude);
uint32_t dist = (EARTH_RADIUS * M_PI / 180) * angle / 1000000;
uint32_t dist = ((uint64_t )EARTH_RADIUS * M_PI / 180) * angle) / 1000000;
uint32_t result = dist * dist;
angle = abs(gpsItem.gps.longitude - gpsItem.pilotLongitude);
dist = gpsItem.distFromEarthAxis * angle / 1000000;
dist = ((uint64_t ) gpsItem.distFromEarthAxis * angle) / 1000000;
result += dist * dist;
// Length on ground (ignoring curvature of the earth)