1
0
Fork 0

Metar: add safe string storage for tied property

This commit is contained in:
James Turner 2021-10-20 13:23:57 +01:00
parent 138a678a30
commit b6e4cbbf14
2 changed files with 9 additions and 2 deletions

View file

@ -204,8 +204,9 @@ static const double thickness_value[] = { 0, 65, 600, 750, 1000 };
const char* MetarProperties::get_metar() const const char* MetarProperties::get_metar() const
{ {
if (!_metar) return ""; if (!_metar || _metarData.empty())
return _metar->getRawDataPtr(); return "";
return _metarData.c_str();
} }
void MetarProperties::set_metar( const char * metarString ) void MetarProperties::set_metar( const char * metarString )
@ -239,9 +240,13 @@ void MetarProperties::setMetar( SGSharedPtr<FGMetar> m )
_metar = m; _metar = m;
_decoded.clear(); _decoded.clear();
if (!m) { if (!m) {
_metarData.clear();
return; return;
} }
// copy the string so we have guranteed storage for get_metar tied property API
_metarData = _metar->getDataString();
const vector<string> weather = m->getWeather(); const vector<string> weather = m->getWeather();
for( vector<string>::const_iterator it = weather.begin(); it != weather.end(); ++it ) { for( vector<string>::const_iterator it = weather.begin(); it != weather.end(); ++it ) {
if( !_decoded.empty() ) _decoded.append(", "); if( !_decoded.empty() ) _decoded.append(", ");

View file

@ -69,6 +69,8 @@ private:
SGPropertyNode_ptr _rootNode; SGPropertyNode_ptr _rootNode;
SGPropertyNode_ptr _metarValidNode; SGPropertyNode_ptr _metarValidNode;
std::string _metarData;
std::string _station_id; std::string _station_id;
double _station_elevation; double _station_elevation;
double _station_latitude; double _station_latitude;