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.
This commit is contained in:
Ryan Curtin
2014-11-10 16:54:12 +00:00
parent 783f28bcf5
commit 8da5cc01b1
+2 -2
View File
@@ -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);