From b6e4cbbf149dbbd97871e645bfd6c61530040943 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 20 Oct 2021 13:23:57 +0100 Subject: [PATCH] Metar: add safe string storage for tied property --- src/Environment/metarproperties.cxx | 9 +++++++-- src/Environment/metarproperties.hxx | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Environment/metarproperties.cxx b/src/Environment/metarproperties.cxx index 94698cb21..fb72baa93 100644 --- a/src/Environment/metarproperties.cxx +++ b/src/Environment/metarproperties.cxx @@ -204,8 +204,9 @@ static const double thickness_value[] = { 0, 65, 600, 750, 1000 }; const char* MetarProperties::get_metar() const { - if (!_metar) return ""; - return _metar->getRawDataPtr(); + if (!_metar || _metarData.empty()) + return ""; + return _metarData.c_str(); } void MetarProperties::set_metar( const char * metarString ) @@ -239,9 +240,13 @@ void MetarProperties::setMetar( SGSharedPtr m ) _metar = m; _decoded.clear(); if (!m) { + _metarData.clear(); return; } + // copy the string so we have guranteed storage for get_metar tied property API + _metarData = _metar->getDataString(); + const vector weather = m->getWeather(); for( vector::const_iterator it = weather.begin(); it != weather.end(); ++it ) { if( !_decoded.empty() ) _decoded.append(", "); diff --git a/src/Environment/metarproperties.hxx b/src/Environment/metarproperties.hxx index e692ddbdc..1b1fb2e35 100644 --- a/src/Environment/metarproperties.hxx +++ b/src/Environment/metarproperties.hxx @@ -69,6 +69,8 @@ private: SGPropertyNode_ptr _rootNode; SGPropertyNode_ptr _metarValidNode; + std::string _metarData; + std::string _station_id; double _station_elevation; double _station_latitude;