Open r-barnes opened 4 years ago
Thanks. Done!
Unfortunately, the problem isn't fixed for me yet.
These lines:
if ( argc < 4 ) {
std::cout << "Too few arguments." << std::endl;
return -1;
}
don't provide helpful feedback if the user enters no arguments.
And eliminating those lines means a segfault here
if ( strcmp( method, "parallel" ) == 0 ) {
if the user enters no arguments.
I think the code would be significantly simplified if you made a test.cpp
which runs the test suite and limited main.cpp
to only taking input datasets. That eliminates the if ( strcmp( method, "parallel" ) == 0 ) {
if-clause which means you can pass all argument checking off to the CLI11 library.
Done! I have provide helpful feedback in the program. If the user enters no arguments., the argc
is less than 4, and the program will exit. I think those lines do not mean a segfault here if ( strcmp( method, "parallel" ) == 0 )
. The input parameters of the two modes are different, I think it is necessary to know which mode it is. Therefore, i kept this line of code if ( strcmp( method, "parallel" ) == 0 )
The code segfaults when running, as follows:
This is because you don't perform any kind of input sanitization or CLI argument validity checking.
I've personally found CLI11 to be useful for this (example). If you decide to use it, you could include it as a submodule (see here). Otherwise, you should check the number of arguments and ensure they're what you expect potentially like this, but I think CLI11 is really the better option.
In any case, the program shouldn't segfault.