Segfault when generating tests with CROSSCOMPILING_EMULATOR set to empty string
Minimum reproducible example:
cmake_minimum_required(VERSION 3.12)
project(test C)
enable_testing()
file(WRITE "${PROJECT_BINARY_DIR}/main.c" "int main(){return 0;}")
add_executable(main "${PROJECT_BINARY_DIR}/main.c")
set_property(TARGET main PROPERTY CROSSCOMPILING_EMULATOR "")
add_test(NAME main COMMAND main)
Running CMake on this causes a segfault.
The offending code is in Source/cmTestGenerator.cxx
starting at line 90:
// Prepend with the emulator when cross compiling if required.
const char* emulator = target->GetProperty("CROSSCOMPILING_EMULATOR");
if (emulator != nullptr) {
std::vector<std::string> emulatorWithArgs;
cmSystemTools::ExpandListArgument(emulator, emulatorWithArgs);
std::string emulatorExe(emulatorWithArgs[0]); // <-- BAD - assumes emulatorWithArgs is not empty
cmSystemTools::ConvertToUnixSlashes(emulatorExe);
os << cmOutputConverter::EscapeForCMake(emulatorExe) << " ";
for (std::vector<std::string>::const_iterator ei =
emulatorWithArgs.begin() + 1;
ei != emulatorWithArgs.end(); ++ei) {
os << cmOutputConverter::EscapeForCMake(*ei) << " ";
}
}
I will fix this myself when I get in tomorrow.
Edited by Kyle Edwards