Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2018-05-19 11:27:46 +0300
committerJunio C Hamano <gitster@pobox.com>2018-05-21 03:58:56 +0300
commit735e4173b3feba0cc495bbb2dd85341b6378f628 (patch)
tree254110f834da6b030ca1e0b0a7490f76c040276d /fsmonitor.c
parentd50b69b868d1b6a7f36e94382c74d2e8cda2d64a (diff)
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 <peff@peff.net> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fsmonitor.c')
-rw-r--r--fsmonitor.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/fsmonitor.c b/fsmonitor.c
index 6d7bcd5d0e..b6fcb0f08f 100644
--- a/fsmonitor.c
+++ b/fsmonitor.c
@@ -97,19 +97,13 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
static int query_fsmonitor(int version, uint64_t last_update, struct strbuf *query_result)
{
struct child_process cp = CHILD_PROCESS_INIT;
- char ver[64];
- char date[64];
- const char *argv[4];
- if (!(argv[0] = core_fsmonitor))
+ if (!core_fsmonitor)
return -1;
- snprintf(ver, sizeof(version), "%d", version);
- snprintf(date, sizeof(date), "%" PRIuMAX, (uintmax_t)last_update);
- argv[1] = ver;
- argv[2] = date;
- argv[3] = NULL;
- cp.argv = argv;
+ argv_array_push(&cp.args, core_fsmonitor);
+ argv_array_pushf(&cp.args, "%d", version);
+ argv_array_pushf(&cp.args, "%" PRIuMAX, (uintmax_t)last_update);
cp.use_shell = 1;
cp.dir = get_git_work_tree();