Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-07-01 13:42:55 +0300
committerJunio C Hamano <gitster@pobox.com>2022-07-01 21:43:43 +0300
commit480a0e30a78a6a86e1ea97059f72e4bf4299d052 (patch)
tree5efaa6159105c86be84e31b1ecbd460c09d98eea /builtin/merge-file.c
parentd90dafbe3180aa0ad095a5f2fa9c83bfa3d3767d (diff)
merge-file: refactor for subsequent memory leak fix
Refactor the code in builtin/merge-file.c to: * Use the initializer to zero out "mmfs", and use modern C syntax for the rest. * Refactor the the inner loop to use a variable and "if/else if" pattern followed by "return". This will make a change to change it to a "goto cleanup" pattern smaller. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/merge-file.c')
-rw-r--r--builtin/merge-file.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index e695867ee5..793817f3cb 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -25,10 +25,10 @@ static int label_cb(const struct option *opt, const char *arg, int unset)
int cmd_merge_file(int argc, const char **argv, const char *prefix)
{
- const char *names[3] = { NULL, NULL, NULL };
- mmfile_t mmfs[3];
- mmbuffer_t result = {NULL, 0};
- xmparam_t xmp = {{0}};
+ const char *names[3] = { 0 };
+ mmfile_t mmfs[3] = { 0 };
+ mmbuffer_t result = { 0 };
+ xmparam_t xmp = { 0 };
int ret = 0, i = 0, to_stdout = 0;
int quiet = 0;
struct option options[] = {
@@ -71,21 +71,23 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
for (i = 0; i < 3; i++) {
char *fname;
- int ret;
+ mmfile_t *mmf = mmfs + i;
if (!names[i])
names[i] = argv[i];
fname = prefix_filename(prefix, argv[i]);
- ret = read_mmfile(mmfs + i, fname);
+
+ if (read_mmfile(mmf, fname))
+ ret = -1;
+ else if (mmf->size > MAX_XDIFF_SIZE ||
+ buffer_is_binary(mmf->ptr, mmf->size))
+ ret = error("Cannot merge binary files: %s",
+ argv[i]);
+
free(fname);
if (ret)
- return -1;
-
- if (mmfs[i].size > MAX_XDIFF_SIZE ||
- buffer_is_binary(mmfs[i].ptr, mmfs[i].size))
- return error("Cannot merge binary files: %s",
- argv[i]);
+ return ret;
}
xmp.ancestor = names[1];