[Lemon-commits] [lemon_svn] klao: r1158 - hugo/trunk/src/test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:43:35 CET 2006


Author: klao
Date: Wed Sep 15 16:25:44 2004
New Revision: 1158

Modified:
   hugo/trunk/src/test/preflow_graph.inp   (props changed)
   hugo/trunk/src/test/preflow_test.cc   (contents, props changed)

Log:
Handling strings with std::string
Do not segfault if srcdir env. variable is not set.


Modified: hugo/trunk/src/test/preflow_test.cc
==============================================================================
--- hugo/trunk/src/test/preflow_test.cc	(original)
+++ hugo/trunk/src/test/preflow_test.cc	Wed Sep 15 16:25:44 2004
@@ -1,4 +1,6 @@
 #include <fstream>
+#include <string>
+
 #include "test_tools.h"
 #include <hugo/smart_graph.h>
 #include <hugo/dimacs.h>
@@ -6,8 +8,6 @@
 #include <hugo/skeletons/graph.h>
 #include <hugo/skeletons/maps.h>
 
-#include <string.h>
-
 using namespace hugo;
 
 void check_Preflow() 
@@ -69,17 +69,17 @@
 
   typedef Preflow<Graph, int> PType;
 
-  char *f_name;
-  
-  f_name=new char[strlen(getenv("srcdir"))+50];
-  strcpy(f_name,getenv("srcdir"));
-  strcat(f_name,"/preflow_graph.inp");
-  
-  std::ifstream file(f_name);
+  string f_name;
+  if( getenv("srcdir") ) {
+    f_name = string(getenv("srcdir")) + "/preflow_graph.inp";
+  }
+  else {
+    f_name = "preflow_graph.inp";
+  }
   
-  check(file,"Input file '" << f_name << "' not found.");
+  std::ifstream file(f_name.c_str());
   
-  delete [] f_name;
+  check(file, "Input file '" << f_name << "' not found.");
   
   Graph G;
   Node s, t;
@@ -180,6 +180,3 @@
 	min_min_cut_value == max_min_cut_value,
 	"The max flow value or the three min cut values are incorrect.");
 }
-
-
-



More information about the Lemon-commits mailing list