BUG: Fixes crashes in unit tests when argv[0] == nullptr#564
BUG: Fixes crashes in unit tests when argv[0] == nullptr#564dzenanz merged 1 commit intoInsightSoftwareConsortium:masterfrom N-Dekker:Fix-Test-argv-nullptr-crashes
Conversation
Many unit tests could crash (or have undefined behavior), when doing something
like the following with `argv[0] == nullptr`:
std::cerr << "Usage: " << argv[0] << std::endl;
This commit prevents such crashes by using a new macro,
`itkNameOfTestExecutableMacro(argv)`, instead of `argv[0]`.
|
This pull request fixes crashes (undefined behavior) from many ITK test drivers, when the user manually selects a test from the command-line interface, for example: Run ITKBiasCorrectionTestDriver. The following output appears: Then type 2 and press Enter Without this fix, it would crash, trying to print When this fix is applied, it won't crash anymore. Instead, it will say: What do you think? |
|
I was bothered by that behavior, but never enough to spend the time to fix it. Thanks Niels! |
|
@N-Dekker I have just bumped into this PR. Very nice 👍 ! I've got two comments whose scope is a little bit broader but related to this topic:
Then the test driver message is also/still misleading right? Even if I usually call the tests by their name, I remember having experienced this, and dot not specifically remember the crash conditions, but I would dare to say that hitting the right number does execute the test (?). If this was not the case, and even if the usage is now printed and this prevents the crash, then test instruction does still not honor the behavior, right? Sorry if I'm missing some piece of information.
Thanks. |
Use the `itkNameOfTestExecutableMacro` to get the test name and prevent the the test from crashing when `argv[0]` is null, as recommended in: InsightSoftwareConsortium/ITK#564
Use the `itkNameOfTestExecutableMacro` to get the test name and prevent the the test from crashing when `argv[0]` is null, as recommended in: InsightSoftwareConsortium/ITK#564
|
I realize that this missed all A PR to change the remaining ones: #2939 |
Many unit tests could crash (or have undefined behavior), when doing something
like the following with
argv[0] == nullptr:This commit prevents such crashes by using a new macro,
itkNameOfTestExecutableMacro(argv), instead ofargv[0].