Skip to content

Commit

Permalink
Fix #839: use stack allocated memory to handle TIG_LS_REMOTE
Browse files Browse the repository at this point in the history
Remove argv_from_env and use memory from the stack to parse the
TIG_LS_REMOTE environment variable in reload_refs.
  • Loading branch information
jonas committed Jul 8, 2018
1 parent 7872d8a commit b405c6a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
1 change: 0 additions & 1 deletion include/tig/argv.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ char *argv_to_string_alloc(const char *argv[], const char *sep);
bool argv_to_string_quoted(const char *argv[SIZEOF_ARG], char *buf, size_t buflen, const char *sep);
bool argv_from_string_no_quotes(const char *argv[SIZEOF_ARG], int *argc, char *cmd);
bool argv_from_string(const char *argv[SIZEOF_ARG], int *argc, char *cmd);
bool argv_from_env(const char **argv, const char *name);
void argv_free(const char *argv[]);
size_t argv_size(const char **argv);
bool argv_append(const char ***argv, const char *arg);
Expand Down
11 changes: 0 additions & 11 deletions src/argv.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,6 @@ argv_from_string(const char *argv[SIZEOF_ARG], int *argc, char *cmd)
return split_argv_string(argv, argc, cmd, false);
}

bool
argv_from_env(const char **argv, const char *name)
{
char *env = argv ? getenv(name) : NULL;
int argc = 0;

if (env && *env)
env = strdup(env);
return !env || argv_from_string(argv, &argc, env);
}

void
argv_free(const char *argv[])
{
Expand Down
13 changes: 8 additions & 5 deletions src/refdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,18 @@ reload_refs(bool force)
const char *ls_remote_argv[SIZEOF_ARG] = {
"git", "show-ref", "--head", "--dereference", NULL
};
static bool init = false;
char ls_remote_cmd[SIZEOF_STR];
struct ref_opt opt = { repo.remote, repo.head, WATCH_NONE };
struct repo_info old_repo = repo;
enum status_code code;
const char *env = getenv("TIG_LS_REMOTE");

if (!init) {
if (!argv_from_env(ls_remote_argv, "TIG_LS_REMOTE"))
return ERROR_OUT_OF_MEMORY;
init = true;
if (env && *env) {
int argc = 0;

string_ncopy(ls_remote_cmd, env, strlen(env));
if (!argv_from_string(ls_remote_argv, &argc, ls_remote_cmd))
return error("Failed to parse TIG_LS_REMOTE: %s", env);
}

if (!*repo.git_dir)
Expand Down

0 comments on commit b405c6a

Please sign in to comment.