[flang-rt] Need to pad the output of execute_command_line(..., CMDMSG) (#185509)

Previously the error message was copied, but not padded for cases where
the message was shorter than the passed CMDMSG string. Add the padding
and also change the test case to test padding on all platforms.
This commit is contained in:
Eugene Epshteyn 2026-03-09 18:34:08 -04:00 committed by GitHub
parent f2dc4897fa
commit a8b726ab9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 13 deletions

View File

@ -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);

View File

@ -360,18 +360,23 @@ TEST_F(ZeroArguments, ECLNotExecutedCommandErrorSync) {
bool wait{true};
OwningPtr<Descriptor> exitStat{IntDescriptor(404)};
OwningPtr<Descriptor> cmdStat{IntDescriptor(202)};
OwningPtr<Descriptor> cmdMsg{CharDescriptor("cmd msg buffer XXXXXXXX")};
// Use longer character string to check padding
OwningPtr<Descriptor> cmdMsg{CharDescriptor(
"Command cannot be executed with exit code: XXXXXXXXXXX.")};
RTNAME(ExecuteCommandLine)
(*command.get(), wait, exitStat.get(), cmdStat.get(), cmdMsg.get());
#ifdef _WIN32
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 9009);
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 5);
CheckDescriptorEqStr(cmdMsg.get(), "Command not found.");
CheckDescriptorEqStr(
cmdMsg.get(), GetPaddedStr("Command not found.", cmdMsg->ElementBytes()));
#else
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 126);
CheckDescriptorEqInt<std::int64_t>(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<Descriptor> commandClean{
CharDescriptor("rm -f NotExecutedCommandFile")};
@ -396,11 +401,13 @@ TEST_F(ZeroArguments, ECLNotFoundCommandErrorSync) {
#ifdef _WIN32
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 9009);
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 5);
CheckDescriptorEqStr(cmdMsg.get(), "Command not found.");
CheckDescriptorEqStr(
cmdMsg.get(), GetPaddedStr("Command not found.", cmdMsg->ElementBytes()));
#else
CheckDescriptorEqInt<std::int64_t>(exitStat.get(), 127);
CheckDescriptorEqInt<std::int64_t>(cmdStat.get(), 5);
CheckDescriptorEqStr(cmdMsg.get(), "Command not found with exit");
CheckDescriptorEqStr(cmdMsg.get(),
GetPaddedStr("Command not found with exit", cmdMsg->ElementBytes()));
#endif
}