]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/props.cxx
Patch from Melchior Franz:
[simgear.git] / simgear / misc / props.cxx
index 8fbbbd585f7952ec14bcca81b45057203516b854..9aeb2385450b8c1e0678dc824dacc35cfa6dec13 100644 (file)
@@ -8,6 +8,10 @@
 
 #include "props.hxx"
 
+#include <algorithm>
+#include <stdio.h>
+#include <string.h>
+
 #if PROPS_STANDALONE
 
 #include <iostream>
@@ -17,7 +21,6 @@ using std::sort;
 
 #else
 
-#include <algorithm>
 #include <simgear/compiler.h>
 #include <simgear/debug/logstream.hxx>
 
@@ -25,9 +28,6 @@ SG_USING_STD(sort);
 
 #endif
 
-#include <stdio.h>
-#include <string.h>
-
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -221,9 +221,8 @@ copy_string (const char * s)
                                // FIXME: potential buffer overflow.
                                // For some reason, strnlen and
                                // strncpy cause all kinds of crashes.
-  string str = s;
-  char * copy = new char[str.size() + 1];
-  strcpy(copy, str.c_str());
+  char * copy = new char[strlen(s) + 1];
+  strcpy(copy, s);
   return copy;
 }
 
@@ -418,7 +417,7 @@ SGPropertyNode::set_string (const char * val)
   if (_tied) {
     return _value.string_val->setValue(val);
   } else {
-    delete (char *)_local_val.string_val;
+    delete [] (char *)_local_val.string_val;
     _local_val.string_val = copy_string(val);
     return true;
   }
@@ -474,7 +473,7 @@ SGPropertyNode::clear_value ()
       delete _value.string_val;
       _value.string_val = 0;
     } else {
-      delete (char *)_local_val.string_val;
+      delete [] (char *)_local_val.string_val;
     }
     _local_val.string_val = 0;
     break;
@@ -676,7 +675,7 @@ SGPropertyNode::SGPropertyNode (const char * name,
  */
 SGPropertyNode::~SGPropertyNode ()
 {
-  delete (char *)_name;
+  delete [] (char *)_name;
   for (int i = 0; i < (int)_children.size(); i++) {
     delete _children[i];
   }