1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-27 16:56:15 +02:00

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>
This commit is contained in:
Elia Pinto 2017-01-13 17:58:00 +00:00 committed by Junio C Hamano
parent d7dffce1ce
commit 8d7aa4ba6a

View File

@ -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;
}