From 8da5cc01b13eb005605c392aec261e59ced5b0f3 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Mon, 10 Nov 2014 16:54:12 +0000 Subject: [PATCH] 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. --- 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 5f7768f5ce..8a929b9d20 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);