Skip to content

Commit

Permalink
Make argv_copy support allocating argv members
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Fonseca authored and jonas committed Jun 3, 2010
1 parent 9d7281d commit c3a7a07
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c3a7a07

Please sign in to comment.