diff --git a/flang-rt/lib/runtime/execute.cpp b/flang-rt/lib/runtime/execute.cpp index b843a0c7f463..4fd6a1e06021 100644 --- a/flang-rt/lib/runtime/execute.cpp +++ b/flang-rt/lib/runtime/execute.cpp @@ -48,19 +48,15 @@ enum CMD_STAT { SIGNAL_ERR = 7 }; -// Override CopyCharsToDescriptor in tools.h, pass string directly -void CopyCharsToDescriptor(const Descriptor &value, const char *rawValue) { - CopyCharsToDescriptor(value, rawValue, std::strlen(rawValue)); -} - -void CheckAndCopyCharsToDescriptor( +static void CheckAndCopyCharsToDescriptor( const Descriptor *value, const char *rawValue) { if (value) { - CopyCharsToDescriptor(*value, rawValue); + CopyAndPad(value->OffsetElement(), rawValue, value->ElementBytes(), + std::strlen(rawValue)); } } -void CheckAndStoreIntToDescriptor( +static void CheckAndStoreIntToDescriptor( const Descriptor *intVal, std::int64_t value, Terminator &terminator) { if (intVal) { StoreIntToDescriptor(intVal, value, terminator); diff --git a/flang-rt/unittests/Runtime/CommandTest.cpp b/flang-rt/unittests/Runtime/CommandTest.cpp index 3bed8acafc59..ed640d426adc 100644 --- a/flang-rt/unittests/Runtime/CommandTest.cpp +++ b/flang-rt/unittests/Runtime/CommandTest.cpp @@ -360,18 +360,23 @@ TEST_F(ZeroArguments, ECLNotExecutedCommandErrorSync) { bool wait{true}; OwningPtr exitStat{IntDescriptor(404)}; OwningPtr cmdStat{IntDescriptor(202)}; - OwningPtr cmdMsg{CharDescriptor("cmd msg buffer XXXXXXXX")}; + // Use longer character string to check padding + OwningPtr cmdMsg{CharDescriptor( + "Command cannot be executed with exit code: XXXXXXXXXXX.")}; RTNAME(ExecuteCommandLine) (*command.get(), wait, exitStat.get(), cmdStat.get(), cmdMsg.get()); #ifdef _WIN32 CheckDescriptorEqInt(exitStat.get(), 9009); CheckDescriptorEqInt(cmdStat.get(), 5); - CheckDescriptorEqStr(cmdMsg.get(), "Command not found."); + CheckDescriptorEqStr( + cmdMsg.get(), GetPaddedStr("Command not found.", cmdMsg->ElementBytes())); #else CheckDescriptorEqInt(exitStat.get(), 126); CheckDescriptorEqInt(cmdStat.get(), 4); - CheckDescriptorEqStr(cmdMsg.get(), "Command cannot be execu"); + CheckDescriptorEqStr(cmdMsg.get(), + GetPaddedStr("Command cannot be executed with exit code: 126.", + cmdMsg->ElementBytes())); // removing the file only on Linux (file is not created on Win) OwningPtr commandClean{ CharDescriptor("rm -f NotExecutedCommandFile")}; @@ -396,11 +401,13 @@ TEST_F(ZeroArguments, ECLNotFoundCommandErrorSync) { #ifdef _WIN32 CheckDescriptorEqInt(exitStat.get(), 9009); CheckDescriptorEqInt(cmdStat.get(), 5); - CheckDescriptorEqStr(cmdMsg.get(), "Command not found."); + CheckDescriptorEqStr( + cmdMsg.get(), GetPaddedStr("Command not found.", cmdMsg->ElementBytes())); #else CheckDescriptorEqInt(exitStat.get(), 127); CheckDescriptorEqInt(cmdStat.get(), 5); - CheckDescriptorEqStr(cmdMsg.get(), "Command not found with exit"); + CheckDescriptorEqStr(cmdMsg.get(), + GetPaddedStr("Command not found with exit", cmdMsg->ElementBytes())); #endif }