certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi/libRTI RTIambassador.cc


From: certi-cvs
Subject: [certi-cvs] certi/libRTI RTIambassador.cc
Date: Mon, 13 Oct 2008 09:38:09 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Petr Gotthard <gotthardp>       08/10/13 09:38:09

Modified files:
        libRTI         : RTIambassador.cc 

Log message:
        Bug #24538: Replaced strdup by new[].

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libRTI/RTIambassador.cc?cvsroot=certi&r1=3.95&r2=3.96

Patches:
Index: RTIambassador.cc
===================================================================
RCS file: /sources/certi/certi/libRTI/RTIambassador.cc,v
retrieving revision 3.95
retrieving revision 3.96
diff -u -b -r3.95 -r3.96
--- RTIambassador.cc    10 Oct 2008 15:18:23 -0000      3.95
+++ RTIambassador.cc    13 Oct 2008 09:38:08 -0000      3.96
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: RTIambassador.cc,v 3.95 2008/10/10 15:18:23 gotthardp Exp $
+// $Id: RTIambassador.cc,v 3.96 2008/10/13 09:38:08 gotthardp Exp $
 // ----------------------------------------------------------------------------
 
 
@@ -85,6 +85,25 @@
     throw RTI::RTIinternalError("");
 }
 
+char *
+hla_strdup(const std::string &s)
+    throw (RTIinternalError)
+{
+    try {
+        size_t len = s.length();
+        // the HLA 1.3 standard defines, that char* must be free-ed by delete[]
+        char *result = new char[len+1];
+        strncpy(result, s.c_str(), len);
+        result[len] = '\0';
+
+        return result;
+    }
+    catch (std::bad_alloc) {
+        throw RTI::RTIinternalError("Cannot allocate memory.");
+    }
+    throw RTI::RTIinternalError("");
+}
+
 } // anonymous namespace
 
 // ----------------------------------------------------------------------------
@@ -2579,7 +2598,7 @@
     req.type = Message::GET_OBJECT_CLASS_NAME ;
     req.setObjectClass(handle);
     privateRefs->executeService(&req, &rep);
-    return strdup(rep.getName().c_str());
+    return hla_strdup(rep.getName());
 }
 
 // ----------------------------------------------------------------------------
@@ -2627,7 +2646,7 @@
     req.setAttribute(theHandle);
     req.setObjectClass(whichClass);
     privateRefs->executeService(&req, &rep);
-    return strdup(rep.getName().c_str());
+    return hla_strdup(rep.getName());
 }
 
 // ----------------------------------------------------------------------------
@@ -2665,7 +2684,7 @@
 
     privateRefs->executeService(&req, &rep);
 
-    return strdup(rep.getName().c_str());
+    return hla_strdup(rep.getName());
 }
 
 // ----------------------------------------------------------------------------
@@ -2709,7 +2728,7 @@
 
     privateRefs->executeService(&req, &rep);
 
-    return strdup(rep.getName().c_str());
+    return hla_strdup(rep.getName());
 }
 
 // ----------------------------------------------------------------------------
@@ -2743,7 +2762,7 @@
 
     privateRefs->executeService(&req, &rep);
 
-    return strdup(rep.getName().c_str());
+    return hla_strdup(rep.getName());
 }
 
 // ----------------------------------------------------------------------------
@@ -2780,7 +2799,7 @@
     req.type = Message::GET_SPACE_NAME ;
     req.setSpace(handle);
     privateRefs->executeService(&req, &rep);
-    return strdup(rep.getName().c_str());
+    return hla_strdup(rep.getName());
 }
 
 // ----------------------------------------------------------------------------
@@ -2824,7 +2843,7 @@
     req.setDimension(dimension);
     req.setSpace(space);
     privateRefs->executeService(&req, &rep);
-    return strdup(rep.getName().c_str());
+    return hla_strdup(rep.getName());
 }
 
 // ----------------------------------------------------------------------------
@@ -2908,7 +2927,7 @@
     req.type = Message::GET_TRANSPORTATION_NAME ;
     req.setTransportation(theHandle);
     privateRefs->executeService(&req, &rep);
-    return(strdup(rep.getName().c_str()));
+    return hla_strdup(rep.getName());
 }
 
 // ----------------------------------------------------------------------------
@@ -2937,7 +2956,7 @@
     req.type = Message::GET_ORDERING_NAME ;
     req.setOrdering(theHandle);
     privateRefs->executeService(&req, &rep);
-    return(strdup(rep.getName().c_str()));
+    return hla_strdup(rep.getName());
 }
 
 // ----------------------------------------------------------------------------
@@ -3045,4 +3064,4 @@
     privateRefs->executeService(&req, &rep);
 }
 
-// $Id: RTIambassador.cc,v 3.95 2008/10/10 15:18:23 gotthardp Exp $
+// $Id: RTIambassador.cc,v 3.96 2008/10/13 09:38:08 gotthardp Exp $




reply via email to

[Prev in Thread] Current Thread [Next in Thread]