diff options
author | Elia Pinto <gitter.spiros@gmail.com> | 2017-01-13 18:58:00 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-01-13 20:22:18 +0100 |
commit | 8d7aa4ba6a00b3ff69261e88b4842c0df5662125 (patch) | |
tree | 058246c75637359eb2ab765ae9f767cae09a0a46 /builtin | |
parent | Fifth batch 2.12 (diff) | |
download | git-8d7aa4ba6a00b3ff69261e88b4842c0df5662125.tar.xz git-8d7aa4ba6a00b3ff69261e88b4842c0df5662125.zip |
builtin/commit.c: remove the PATH_MAX limitation via dynamic allocation
Remove the PATH_MAX limitation from the environment setting that
points to a filename by switching to dynamic allocation.
As a side effect of this change, we also reduce the snprintf()
calls, that may silently truncate results if the programmer is not
careful.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/commit.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index 711f96cc43..276c4f2e7e 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -960,15 +960,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix, return 0; if (use_editor) { - char index[PATH_MAX]; - const char *env[2] = { NULL }; - env[0] = index; - snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); - if (launch_editor(git_path_commit_editmsg(), NULL, env)) { + struct argv_array env = ARGV_ARRAY_INIT; + + argv_array_pushf(&env, "GIT_INDEX_FILE=%s", index_file); + if (launch_editor(git_path_commit_editmsg(), NULL, env.argv)) { fprintf(stderr, _("Please supply the message using either -m or -F option.\n")); exit(1); } + argv_array_clear(&env); } if (!no_verify && @@ -1557,23 +1557,22 @@ static int run_rewrite_hook(const unsigned char *oldsha1, int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...) { - const char *hook_env[3] = { NULL }; - char index[PATH_MAX]; + struct argv_array hook_env = ARGV_ARRAY_INIT; va_list args; int ret; - snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); - hook_env[0] = index; + argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file); /* * Let the hook know that no editor will be launched. */ if (!editor_is_used) - hook_env[1] = "GIT_EDITOR=:"; + argv_array_push(&hook_env, "GIT_EDITOR=:"); va_start(args, name); - ret = run_hook_ve(hook_env, name, args); + ret = run_hook_ve(hook_env.argv,name, args); va_end(args); + argv_array_clear(&hook_env); return ret; } |