@@ -57,18 +57,16 @@ static bool IsValidIntDescriptor(const Descriptor *length) {
57
57
length->type ().IsInteger () && typeCode && typeCode->second != 1 ;
58
58
}
59
59
60
- void CopyToDescriptor (const Descriptor &value, const char *rawValue,
61
- std::int64_t rawValueLength, std::size_t offset = 0 ) {
62
- std::int64_t toCopy{std::min (rawValueLength,
63
- static_cast <std::int64_t >(value.ElementBytes () - offset))};
64
-
60
+ void CopyToDescriptor (
61
+ const Descriptor &value, const char *rawValue, std::size_t offset = 0 ) {
62
+ auto toCopy{std::min (std::strlen (rawValue), value.ElementBytes () - offset)};
65
63
std::memcpy (value.OffsetElement (offset), rawValue, toCopy);
66
64
}
67
65
68
- void CheckAndCopyToDescriptor (const Descriptor *value, const char *rawValue,
69
- std:: int64_t rawValueLength , std::size_t offset = 0 ) {
66
+ void CheckAndCopyToDescriptor (
67
+ const Descriptor *value, const char *rawValue , std::size_t offset = 0 ) {
70
68
if (value) {
71
- CopyToDescriptor (*value, rawValue, rawValueLength, offset);
69
+ CopyToDescriptor (*value, rawValue, offset);
72
70
}
73
71
}
74
72
@@ -107,7 +105,7 @@ int TerminationCheck(int status, const Descriptor *cmdstat,
107
105
terminator.Crash (" Execution error with system status code: %d" , status);
108
106
} else {
109
107
CheckAndStoreIntToDescriptor (cmdstat, EXECL_ERR, terminator);
110
- CopyToDescriptor (*cmdmsg, " Execution error" , 15 );
108
+ CopyToDescriptor (*cmdmsg, " Execution error" );
111
109
}
112
110
}
113
111
#ifdef _WIN32
@@ -123,7 +121,7 @@ int TerminationCheck(int status, const Descriptor *cmdstat,
123
121
" Invalid command quit with exit status code: %d" , exitStatusVal);
124
122
} else {
125
123
CheckAndStoreIntToDescriptor (cmdstat, INVALID_CL_ERR, terminator);
126
- CopyToDescriptor (*cmdmsg, " Invalid command line" , 20 );
124
+ CopyToDescriptor (*cmdmsg, " Invalid command line" );
127
125
}
128
126
}
129
127
#if defined(WIFSIGNALED) && defined(WTERMSIG)
@@ -132,7 +130,7 @@ int TerminationCheck(int status, const Descriptor *cmdstat,
132
130
terminator.Crash (" killed by signal: %d" , WTERMSIG (status));
133
131
} else {
134
132
CheckAndStoreIntToDescriptor (cmdstat, SIGNAL_ERR, terminator);
135
- CopyToDescriptor (*cmdmsg, " killed by signal" , 18 );
133
+ CopyToDescriptor (*cmdmsg, " killed by signal" );
136
134
}
137
135
}
138
136
#endif
@@ -142,7 +140,7 @@ int TerminationCheck(int status, const Descriptor *cmdstat,
142
140
terminator.Crash (" stopped by signal: %d" , WSTOPSIG (status));
143
141
} else {
144
142
CheckAndStoreIntToDescriptor (cmdstat, SIGNAL_ERR, terminator);
145
- CopyToDescriptor (*cmdmsg, " stopped by signal" , 17 );
143
+ CopyToDescriptor (*cmdmsg, " stopped by signal" );
146
144
}
147
145
}
148
146
#endif
@@ -151,7 +149,7 @@ int TerminationCheck(int status, const Descriptor *cmdstat,
151
149
152
150
const char *ensureNullTerminated (
153
151
const char *str, size_t length, Terminator &terminator) {
154
- if (length < strlen (str)) {
152
+ if (length <= strlen (str)) {
155
153
char *newCmd{(char *)malloc (length + 1 )};
156
154
if (newCmd == NULL ) {
157
155
terminator.Crash (" Command not null-terminated, memory allocation failed "
@@ -175,7 +173,6 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
175
173
176
174
if (exitstat) {
177
175
RUNTIME_CHECK (terminator, IsValidIntDescriptor (exitstat));
178
- // If sync, assigned processor-dependent exit status. Otherwise unchanged
179
176
}
180
177
181
178
if (cmdstat) {
@@ -192,6 +189,7 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
192
189
// either wait is not specified or wait is true: synchronous mode
193
190
int status{std::system (newCmd)};
194
191
int exitStatusVal{TerminationCheck (status, cmdstat, cmdmsg, terminator)};
192
+ // If sync, assigned processor-dependent exit status. Otherwise unchanged
195
193
CheckAndStoreIntToDescriptor (exitstat, exitStatusVal, terminator);
196
194
} else {
197
195
// Asynchronous mode
@@ -232,7 +230,7 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
232
230
" CreateProcess failed with error code: %lu." , GetLastError ());
233
231
} else {
234
232
StoreIntToDescriptor (cmdstat, (uint32_t )GetLastError (), terminator);
235
- CheckAndCopyToDescriptor (cmdmsg, " CreateProcess failed." , 21 );
233
+ CheckAndCopyToDescriptor (cmdmsg, " CreateProcess failed." );
236
234
}
237
235
}
238
236
delete[] wcmd;
@@ -245,7 +243,7 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
245
243
terminator.Crash (" Fork failed with pid: %d." , pid);
246
244
} else {
247
245
StoreIntToDescriptor (cmdstat, FORK_ERR, terminator);
248
- CheckAndCopyToDescriptor (cmdmsg, " Fork failed" , 11 );
246
+ CheckAndCopyToDescriptor (cmdmsg, " Fork failed" );
249
247
}
250
248
} else if (pid == 0 ) {
251
249
int status{std::system (newCmd)};
0 commit comments