[mlpack-svn] r17313 - mlpack/trunk/src/mlpack/tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Nov 10 11:54:13 EST 2014


Author: rcurtin
Date: Mon Nov 10 11:54:12 2014
New Revision: 17313

Log:
strlen() returns the length of the string but you must account for the null
terminator yourself.  Hence, this code sometimes caused random invalid writes
and crashes.


Modified:
   mlpack/trunk/src/mlpack/tests/cli_test.cpp

Modified: mlpack/trunk/src/mlpack/tests/cli_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/cli_test.cpp	(original)
+++ mlpack/trunk/src/mlpack/tests/cli_test.cpp	Mon Nov 10 11:54:12 2014
@@ -121,8 +121,8 @@
   // Now, if we specify this flag, it should be true.
   int argc = 2;
   char* argv[2];
-  argv[0] = strcpy(new char[strlen("programname")], "programname");
-  argv[1] = strcpy(new char[strlen("--flag_test")], "--flag_test");
+  argv[0] = strcpy(new char[strlen("programname") + 1], "programname");
+  argv[1] = strcpy(new char[strlen("--flag_test") + 1], "--flag_test");
 
   CLI::ParseCommandLine(argc, argv);
 



More information about the mlpack-svn mailing list