Skip to content

Commit bf6f546

Browse files
kfazibradking
authored andcommitted
Fix allocation in CROSSCOMPILING_EMULATOR evaluation
In commit fec441e (Teach CROSSCOMPILING_EMULATOR to support arguments, 2019-05-30, v3.15.0-rc1~6^2) the new member `cmCustomCommandGenerator::EmulatorsWithArguments` was not initialized to the proper size. Fix this and add a test case covering the crash that could occur with multiple commands where an emulator appears only in a later command. Fixes: #19500 Co-Author: Brad King <[email protected]>
1 parent 79bcf4e commit bf6f546

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Source/cmCustomCommandGenerator.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
2525
, OldStyle(cc.GetEscapeOldStyle())
2626
, MakeVars(cc.GetEscapeAllowMakeVars())
2727
, GE(new cmGeneratorExpression(cc.GetBacktrace()))
28+
, EmulatorsWithArguments(cc.GetCommandLines().size())
2829
{
2930
const cmCustomCommandLines& cmdlines = this->CC.GetCommandLines();
3031
for (cmCustomCommandLine const& cmdline : cmdlines) {
@@ -107,7 +108,6 @@ void cmCustomCommandGenerator::FillEmulatorsWithArguments()
107108
continue;
108109
}
109110

110-
this->EmulatorsWithArguments.emplace_back();
111111
cmSystemTools::ExpandListArgument(emulator_property,
112112
this->EmulatorsWithArguments[c]);
113113
}

Tests/RunCMake/CrosscompilingEmulator/AddCustomCommand.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,22 @@ add_custom_command(OUTPUT output2
2626

2727
# DoesNotUseEmulator: The command will fail if emulator is prepended
2828
add_custom_command(OUTPUT output3
29+
COMMAND ${CMAKE_COMMAND} -E echo generated_exe_emulator_unexpected
2930
COMMAND $<TARGET_FILE:generated_exe_emulator_unexpected>
3031
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/output3
3132
DEPENDS generated_exe_emulator_unexpected)
3233

3334
# DoesNotUseEmulator: The command will fail if emulator is prepended
3435
add_custom_command(OUTPUT outputImp
36+
COMMAND ${CMAKE_COMMAND} -E echo generated_exe_emulator_unexpected_imported
3537
COMMAND generated_exe_emulator_unexpected_imported
3638
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/outputImp
3739
)
3840

3941
# UsesEmulator: The command only succeeds if the emulator is prepended
4042
# to the command.
4143
add_custom_command(OUTPUT output4
44+
COMMAND ${CMAKE_COMMAND} -E echo generated_exe_emulator_expected
4245
COMMAND generated_exe_emulator_expected
4346
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/output4
4447
DEPENDS generated_exe_emulator_expected)

0 commit comments

Comments
 (0)