Skip to content

Commit 26b8027

Browse files
authored
Merge pull request diffblue#7738 from tautschnig/bugfixes/piped-process
Piped process: fix off-by-one error
2 parents 35f348c + c47e940 commit 26b8027

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/util/piped_process.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ piped_processt::piped_processt(
277277
dup2(pipe_output[1], STDOUT_FILENO);
278278
dup2(pipe_output[1], STDERR_FILENO);
279279

280-
// Create a char** for the arguments (all the contents of commandvec
281-
// except the first element, i.e. the command itself).
282-
char **args =
283-
reinterpret_cast<char **>(malloc((commandvec.size()) * sizeof(char *)));
280+
// Create a char** for the arguments plus a NULL terminator (by convention,
281+
// the first "argument" is the command itself)
282+
char **args = reinterpret_cast<char **>(
283+
malloc((commandvec.size() + 1) * sizeof(char *)));
284284
// Add all the arguments to the args array of char *.
285285
unsigned long i = 0;
286286
while(i < commandvec.size())

0 commit comments

Comments
 (0)