From de38157916ac06e19c47fd3b596ec18329771ed1 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Fri, 28 Feb 2014 17:34:41 +0100 Subject: [PATCH] FGPUIDialog: fix reading from already free'd memory. Calls to updateValues can cause nested calls invalidating the char* passed as argument, if retrieved from a SGPropertyNode. Probably SGPropertyNode should also be modified to return a std::string instead of a pointer to an internal buffer. --- src/GUI/FGPUIDialog.cxx | 20 +++++++------------- src/GUI/FGPUIDialog.hxx | 12 ++++++------ src/GUI/dialog.hxx | 16 +++++++--------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/GUI/FGPUIDialog.cxx b/src/GUI/FGPUIDialog.cxx index a7e2dddbf..ead9cc91c 100644 --- a/src/GUI/FGPUIDialog.cxx +++ b/src/GUI/FGPUIDialog.cxx @@ -711,17 +711,14 @@ FGPUIDialog::~FGPUIDialog () } void -FGPUIDialog::updateValues (const char *objectName) +FGPUIDialog::updateValues(const std::string& objectName) { - if (objectName && !objectName[0]) - objectName = 0; - for (unsigned int i = 0; i < _propertyObjects.size(); i++) { const string &name = _propertyObjects[i]->name; - if (objectName && name != objectName) { + + if( !objectName.empty() && name != objectName ) continue; - } - + puObject *widget = _propertyObjects[i]->object; int widgetType = widget->getType(); if (widgetType & PUCLASS_LIST) { @@ -742,15 +739,12 @@ FGPUIDialog::updateValues (const char *objectName) } void -FGPUIDialog::applyValues (const char *objectName) +FGPUIDialog::applyValues(const std::string& objectName) { - if (objectName && !objectName[0]) - objectName = 0; - for (unsigned int i = 0; i < _propertyObjects.size(); i++) { const string &name = _propertyObjects[i]->name; - if (objectName && name != objectName) - continue; + if( !objectName.empty() && name != objectName ) + continue; copy_from_pui(_propertyObjects[i]->object, _propertyObjects[i]->node); diff --git a/src/GUI/FGPUIDialog.hxx b/src/GUI/FGPUIDialog.hxx index a21c4ec8c..104760cfa 100644 --- a/src/GUI/FGPUIDialog.hxx +++ b/src/GUI/FGPUIDialog.hxx @@ -62,28 +62,28 @@ public: /** * Update the values of all GUI objects with a specific name, - * or all if name is 0 (default). + * or all if an empty name is given (default). * * This method copies values from the FlightGear property tree to * the GUI object(s). * * @param objectName The name of the GUI object(s) to update. - * Use the empty name for all unnamed objects. + * Use the empty name for all objects. */ - virtual void updateValues (const char * objectName = 0); + virtual void updateValues(const std::string& objectName = ""); /** * Apply the values of all GUI objects with a specific name, - * or all if name is 0 (default) + * or all if an empty name is given (default). * * This method copies values from the GUI object(s) to the * FlightGear property tree. * * @param objectName The name of the GUI object(s) to update. - * Use the empty name for all unnamed objects. + * Use the empty name for all objects. */ - virtual void applyValues (const char * objectName = 0); + virtual void applyValues(const std::string& objectName = ""); /** diff --git a/src/GUI/dialog.hxx b/src/GUI/dialog.hxx index 7aa4adc80..e79d8ea3e 100644 --- a/src/GUI/dialog.hxx +++ b/src/GUI/dialog.hxx @@ -3,9 +3,7 @@ #ifndef __DIALOG_HXX #define __DIALOG_HXX 1 -#ifndef __cplusplus -# error This library requires C++ -#endif +#include // forward decls class SGPropertyNode; @@ -32,28 +30,28 @@ public: /** * Update the values of all GUI objects with a specific name, - * or all if name is 0 (default). + * or all if an empty name is given (default). * * This method copies values from the FlightGear property tree to * the GUI object(s). * * @param objectName The name of the GUI object(s) to update. - * Use the empty name for all unnamed objects. + * Use the empty name for all objects. */ - virtual void updateValues (const char * objectName = 0) = 0; + virtual void updateValues(const std::string& objectName = "") = 0; /** * Apply the values of all GUI objects with a specific name, - * or all if name is 0 (default) + * or all if an empty name is given (default) * * This method copies values from the GUI object(s) to the * FlightGear property tree. * * @param objectName The name of the GUI object(s) to update. - * Use the empty name for all unnamed objects. + * Use the empty name for all objects. */ - virtual void applyValues (const char * objectName = 0) = 0; + virtual void applyValues(const std::string& objectName = "") = 0; /** -- 2.39.2