Browse Source

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>
maint
Elia Pinto 8 years ago committed by Junio C Hamano
parent
commit
8d7aa4ba6a
  1. 21
      builtin/commit.c

21
builtin/commit.c

@ -960,15 +960,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix, @@ -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, @@ -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;
}

Loading…
Cancel
Save