run_external_diff: use an argv_array for the environment

We currently use static buffers and a static array for formatting the environment passed to the external diff. There's nothing wrong in the code, but it is much easier to verify that it is correct if we use a dynamic argv_array. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 19, 2014 at 15:17 UTC ae049c955c8858899467f6c5c0259c48a5294385
1 file changed +5 -9
diff.c
+5 -9
@@ -2908,11 +2908,9 @@ static void run_external_diff(const char *pgm,
2908 struct diff_options *o)
2909 {
2910 struct argv_array argv = ARGV_ARRAY_INIT;
2911 + struct argv_array env = ARGV_ARRAY_INIT;
2912 int retval;
2913 struct diff_queue_struct *q = &diff_queued_diff;
2913 - const char *env[3] = { NULL };
2914 - char env_counter[50];
2915 - char env_total[50];
2914
2915 if (one && two) {
2916 struct diff_tempfile *temp_one, *temp_two;
@@ -2937,15 +2935,13 @@ static void run_external_diff(const char *pgm,
2935 }
2936 fflush(NULL);
2937
2940 - env[0] = env_counter;
2941 - snprintf(env_counter, sizeof(env_counter), "GIT_DIFF_PATH_COUNTER=%d",
2942 - ++o->diff_path_counter);
2943 - env[1] = env_total;
2944 - snprintf(env_total, sizeof(env_total), "GIT_DIFF_PATH_TOTAL=%d", q->nr);
2938 + argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter);
2939 + argv_array_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr);
2940
2946 - retval = run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env);
2941 + retval = run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env.argv);
2942 remove_tempfile();
2943 argv_array_clear(&argv);
2944 + argv_array_clear(&env);
2945 if (retval) {
2946 fprintf(stderr, "external diff died, stopping at %s.\n", name);
2947 exit(1);