[mlpack] 85/149: 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.

Barak A. Pearlmutter barak+git at pearlmutter.net
Sat May 2 09:11:12 UTC 2015


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit e6f0525e628125c4289dd552ff7ab3b6906c7c24
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
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.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17313 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 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);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list