Skip to content

Commit d35163c

Browse files
committed
Make patch arguments more extensible in apply_patch()
It's difficult to conditionally add additional arguments to the patch execution in apply_patch() because they are placed within a compound literal array. Make the arguments more extensible by creating a local array and an index variable to place the next argument into the array. This way, it's much easier to change the number of arguments provided at runtime.
1 parent 7b7dcca commit d35163c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/interdiff.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,9 @@ output_patch1_only (FILE *p1, FILE *out, int not_reverted)
936936
static int
937937
apply_patch (FILE *patch, const char *file, int reverted)
938938
{
939+
#define MAX_PATCH_ARGS 4
940+
const char *argv[MAX_PATCH_ARGS];
941+
int argc = 0;
939942
const char *basename;
940943
unsigned long orig_lines, new_lines;
941944
size_t linelen;
@@ -959,10 +962,14 @@ apply_patch (FILE *patch, const char *file, int reverted)
959962
}
960963
}
961964

962-
w = xpipe(PATCH, &child, "w", (char **) (const char *[]) { PATCH,
963-
reverted ? (has_ignore_all_space ? "-Rlsp0" : "-Rsp0")
964-
: (has_ignore_all_space ? "-lsp0" : "-sp0"),
965-
file, NULL });
965+
/* Add up to MAX_PATCH_ARGS arguments for the patch execution */
966+
argv[argc++] = PATCH;
967+
argv[argc++] = reverted ? (has_ignore_all_space ? "-Rlsp0" : "-Rsp0")
968+
: (has_ignore_all_space ? "-lsp0" : "-sp0");
969+
argv[argc++] = file;
970+
argv[argc++] = NULL;
971+
972+
w = xpipe(PATCH, &child, "w", (char **) argv);
966973

967974
fprintf (w, "--- %s\n+++ %s\n", basename, basename);
968975
line = NULL;

0 commit comments

Comments
 (0)