]> git.mxchange.org Git - flightgear.git/commitdiff
FGPUIDialog: fix reading from already free'd memory.
authorThomas Geymayer <tomgey@gmail.com>
Fri, 28 Feb 2014 16:34:41 +0000 (17:34 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Fri, 28 Feb 2014 16:34:41 +0000 (17:34 +0100)
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
src/GUI/FGPUIDialog.hxx
src/GUI/dialog.hxx

index a7e2dddbf08198d548298bba3162179faea534de..ead9cc91c50c93075adc1c3ddb9b5de15686f593 100644 (file)
@@ -711,17 +711,14 @@ FGPUIDialog::~FGPUIDialog ()
 }
 
 void
 }
 
 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;
   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;
       continue;
-    }
-    
+
     puObject *widget = _propertyObjects[i]->object;
     int widgetType = widget->getType();
     if (widgetType & PUCLASS_LIST) {
     puObject *widget = _propertyObjects[i]->object;
     int widgetType = widget->getType();
     if (widgetType & PUCLASS_LIST) {
@@ -742,15 +739,12 @@ FGPUIDialog::updateValues (const char *objectName)
 }
 
 void
 }
 
 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;
     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);
 
         copy_from_pui(_propertyObjects[i]->object,
                       _propertyObjects[i]->node);
index a21c4ec8c575b4d98d7edf29a2c34e3707ca2514..104760cfacb48157d9e1ad5aabbbf504eeb5cd35 100644 (file)
@@ -62,28 +62,28 @@ public:
 
     /**
      * Update the values of all GUI objects with a specific name,
 
     /**
      * 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.
      *
      * 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,
 
 
     /**
      * 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.
      *
      * 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 = "");
 
 
     /**
 
 
     /**
index 7aa4adc80e6e57ce82afe9846c1ea379fda0ed27..e79d8ea3ee0b7aa1fb612b33a35a1fe39e1ec258 100644 (file)
@@ -3,9 +3,7 @@
 #ifndef __DIALOG_HXX
 #define __DIALOG_HXX 1
 
 #ifndef __DIALOG_HXX
 #define __DIALOG_HXX 1
 
-#ifndef __cplusplus
-# error This library requires C++
-#endif
+#include <string>
 
 // forward decls
 class SGPropertyNode;
 
 // forward decls
 class SGPropertyNode;
@@ -32,28 +30,28 @@ public:
 
     /**
      * Update the values of all GUI objects with a specific name,
 
     /**
      * 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.
      *
      * 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,
 
 
     /**
      * 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.
      *
      * 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;
 
 
     /**
 
 
     /**