Skip to content

Commit 735e417

Browse files
rscharfegitster
authored andcommitted
fsmonitor: use internal argv_array of struct child_process
Avoid magic array sizes and indexes by constructing the fsmonitor command line using the embedded argv_array of the child_process. The resulting code is shorter and easier to extend. Getting rid of the snprintf() calls is a bonus -- even though the buffers were big enough here to avoid truncation -- as it makes auditing the remaining callers easier. Inspired-by: Jeff King <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d50b69b commit 735e417

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

fsmonitor.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,13 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
9797
static int query_fsmonitor(int version, uint64_t last_update, struct strbuf *query_result)
9898
{
9999
struct child_process cp = CHILD_PROCESS_INIT;
100-
char ver[64];
101-
char date[64];
102-
const char *argv[4];
103100

104-
if (!(argv[0] = core_fsmonitor))
101+
if (!core_fsmonitor)
105102
return -1;
106103

107-
snprintf(ver, sizeof(version), "%d", version);
108-
snprintf(date, sizeof(date), "%" PRIuMAX, (uintmax_t)last_update);
109-
argv[1] = ver;
110-
argv[2] = date;
111-
argv[3] = NULL;
112-
cp.argv = argv;
104+
argv_array_push(&cp.args, core_fsmonitor);
105+
argv_array_pushf(&cp.args, "%d", version);
106+
argv_array_pushf(&cp.args, "%" PRIuMAX, (uintmax_t)last_update);
113107
cp.use_shell = 1;
114108
cp.dir = get_git_work_tree();
115109

0 commit comments

Comments
 (0)