[mlpack-git] master: 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. (8da5cc0)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:02:54 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 8da5cc01b13eb005605c392aec261e59ced5b0f3
Author: Ryan Curtin <ryan at ratml.org>
Date: Mon Nov 10 16:54:12 2014 +0000
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.
>---------------------------------------------------------------
8da5cc01b13eb005605c392aec261e59ced5b0f3
src/mlpack/tests/cli_test.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/mlpack/tests/cli_test.cpp b/src/mlpack/tests/cli_test.cpp
index 5f7768f..8a929b9 100644
--- a/src/mlpack/tests/cli_test.cpp
+++ b/src/mlpack/tests/cli_test.cpp
@@ -121,8 +121,8 @@ BOOST_AUTO_TEST_CASE(TestBooleanOption)
// 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-git
mailing list