Fix segfault if number is bigger than size of airports

This commit is contained in:
Roland Winklmeier
2018-10-05 11:56:04 +02:00
committed by Klaus Basan
parent f3f3ebc306
commit bd222f3c97

View File

@@ -12,6 +12,7 @@
#include <XPLM/XPLMPlanes.h>
#include <XPLM/XPLMUtilities.h>
#include "blackmisc/simulation/xplane/qtfreeutils.h"
#include <algorithm>
// clazy:excludeall=reserve-candidates
@@ -684,6 +685,8 @@ namespace XSwiftBus
return calculateGreatCircleDistance(a, ref) < calculateGreatCircleDistance(b, ref);
};
number = std::min(static_cast<int>(m_airports.size()), number);
auto closestAirports = m_airports;
std::partial_sort(closestAirports.begin(), closestAirports.begin() + number, closestAirports.end(), compareFunction);
closestAirports.resize(number);