Skip to content

Commit b4c6759

Browse files
committed
copy: fix file concatenation when invoked via COMMAND /C
The COPY command with file concatenation (e.g., `copy /b a+b dest`) fails with "Source and destination cannot match" when invoked via `COMMAND /C`, such as when nmake executes makefile commands. Root cause: The /C handler builds cmd_line by concatenating argv elements with spaces, always adding a trailing space after the last argument. In expand_pluses(), `strrchr(cmd_args, ' ')` then finds this trailing space instead of the space before the destination filename, causing the destination to be effectively empty. Example with trailing space from /C: Input: "/b msload.com+msbio.cl1 io.sys " last_arg = strrchr(..., ' ') -> points to trailing " " Output: "/b msload.com ;msbio.cl1 io.sys " Result: first file group has no destination, defaults to source This bug was introduced in commit 234e221 ("copy: support any amount of pluses [fixes #94]"). The previous implementation was immune to trailing spaces because it used forward-searching (strchr from after the +) rather than backward-searching (strrchr from end of string). Fix: Strip trailing spaces from cmd_args_bkp before finding last_arg.
1 parent 57f199e commit b4c6759

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/command.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,12 @@ static int expand_pluses(void)
21622162
int len;
21632163
char *p, *p2, *last_arg;
21642164

2165+
if (!strchr(cmd_args, '+'))
2166+
return 0;
21652167
strcpy(cmd_args_bkp, cmd_args);
2168+
len = strlen(cmd_args_bkp);
2169+
while (len > 0 && cmd_args_bkp[len-1] == ' ')
2170+
cmd_args_bkp[--len] = '\0';
21662171
last_arg = strrchr(cmd_args_bkp, ' ');
21672172
if (!last_arg)
21682173
{

0 commit comments

Comments
 (0)