From: Jonas Fonseca Date: Wed, 2 Jun 2010 15:58:35 +0000 (-0400) Subject: Make argv_copy support allocating argv members X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c3a7a0786471a54310966520e4eddb37241e40eb;p=tig.git Make argv_copy support allocating argv members --- diff --git a/tig.c b/tig.c index bfa88e8..1bf95cd 100644 --- a/tig.c +++ b/tig.c @@ -688,13 +688,15 @@ argv_free(const char *argv[]) argv[0] = NULL; } -static void -argv_copy(const char *dst[], const char *src[]) +static bool +argv_copy(const char *dst[], const char *src[], bool allocate) { int argc; for (argc = 0; src[argc]; argc++) - dst[argc] = src[argc]; + if (!(dst[argc] = allocate ? strdup(src[argc]) : src[argc])) + return FALSE; + return TRUE; } @@ -748,7 +750,7 @@ static void io_prepare(struct io *io, const char *dir, enum io_type type, const char *argv[]) { io_init(io, dir, type); - argv_copy(io->argv, argv); + argv_copy(io->argv, argv, FALSE); } static bool @@ -1743,7 +1745,7 @@ add_run_request(enum keymap keymap, int key, int argc, const char **argv) req->key = key; req->argv[0] = NULL; - if (!format_argv(req->argv, argv, FORMAT_NONE)) + if (!argv_copy(req->argv, argv, TRUE)) return REQ_NONE; return REQ_NONE + ++run_requests;