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,
return 0; return 0;


if (use_editor) { if (use_editor) {
char index[PATH_MAX]; struct argv_array env = ARGV_ARRAY_INIT;
const char *env[2] = { NULL };
env[0] = index; argv_array_pushf(&env, "GIT_INDEX_FILE=%s", index_file);
snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); if (launch_editor(git_path_commit_editmsg(), NULL, env.argv)) {
if (launch_editor(git_path_commit_editmsg(), NULL, env)) {
fprintf(stderr, fprintf(stderr,
_("Please supply the message using either -m or -F option.\n")); _("Please supply the message using either -m or -F option.\n"));
exit(1); exit(1);
} }
argv_array_clear(&env);
} }


if (!no_verify && 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, ...) int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...)
{ {
const char *hook_env[3] = { NULL }; struct argv_array hook_env = ARGV_ARRAY_INIT;
char index[PATH_MAX];
va_list args; va_list args;
int ret; int ret;


snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
hook_env[0] = index;


/* /*
* Let the hook know that no editor will be launched. * Let the hook know that no editor will be launched.
*/ */
if (!editor_is_used) if (!editor_is_used)
hook_env[1] = "GIT_EDITOR=:"; argv_array_push(&hook_env, "GIT_EDITOR=:");


va_start(args, name); va_start(args, name);
ret = run_hook_ve(hook_env, name, args); ret = run_hook_ve(hook_env.argv,name, args);
va_end(args); va_end(args);
argv_array_clear(&hook_env);


return ret; return ret;
} }

Loading…
Cancel
Save