From 148c5bdbfb7a1d6633e7b00b39e83a71a86fd047 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 22 Aug 2011 21:18:26 +1000 Subject: [PATCH] Fix use of uninitialised vars in merge2. This makes valgrind happier. Signed-off-by: NeilBrown --- merge2.c | 36 +++++++++++++++++++----------------- wiggle.h | 5 +++-- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/merge2.c b/merge2.c index b50bb06..280f3fa 100644 --- a/merge2.c +++ b/merge2.c @@ -86,7 +86,7 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf, /* A conflict indicates that something is definitely wrong * and so we need to be a bit suspicious of nearby apparent matches. * To display a conflict effectively we expands it's effect to - * include any Extraneous, Unmatched or Changed text. + * include any Extraneous, Unmatched, Changed or AlreadyApplied text. * Also, unless 'words', we need to include any partial lines * in the Unchanged text that forms the border of a conflict. * @@ -120,7 +120,7 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf, m[j].lo = 0; } else if (m[j].type == Changed) { /* This can no longer form a border */ - m[j].lo = 0; m[j].hi = -1; + m[j].hi = -1; /* We merge these conflicts and stop searching */ cnt--; break; @@ -148,7 +148,7 @@ static int isolate_conflicts(struct file af, struct file bf, struct file cf, /* no start-of-line found... */ m[j].hi = -1; if (m[j].hi > 0 && m[j].type == Changed) { - /* this can only work if start is also a linke break */ + /* this can only work if start is also a line break */ if ((m[j].a == 0 || ends_line(af.list[m[j].a-1])) && (m[j].b == 0 || ends_line(bf.list[m[j].b-1])) && (m[j].c == 0 || ends_line(cf.list[m[j].c-1]))) @@ -385,9 +385,11 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c /* need to print from 'hi' to 'lo' of next * Unchanged which is < it's hi */ - int st = m->hi; - if (m->hi <= m->lo) - st = 0; + int st = 0, st1; + if (m->type == Unchanged || m->type == Changed) + if (m->hi >= m->lo) + st = m->hi; + st1 = st; if (m->type == Unchanged) printrange(out, a, m->a+m->lo, m->hi - m->lo); @@ -417,35 +419,35 @@ struct ci print_merge2(FILE *out, struct file *a, struct file *b, struct file *c printrange(out, a, cm->a, cm->lo); break; } - printrange(out, a, cm->a+st, cm->al-st); - st = 0; + printrange(out, a, cm->a+st1, cm->al-st1); + st1 = 0; } fputs(words?"|||":"|||||||\n", out); - st = m->hi; + st1 = st; for (cm=m; cm->in_conflict; cm++) { if ((cm->type == Unchanged || cm->type == Changed) && cm != m && cm->lo < cm->hi) { printrange(out, b, cm->b, cm->lo); break; } - printrange(out, b, cm->b+st, cm->bl-st); - st = 0; + printrange(out, b, cm->b+st1, cm->bl-st1); + st1 = 0; } fputs(words?"===":"=======\n", out); - st = m->hi; + st1 = st; for (cm=m; cm->in_conflict; cm++) { if (cm->type == Unchanged && cm != m && cm->lo < cm->hi) { printrange(out, c, cm->c, cm->lo); break; } if (cm->type == Changed) - st = 0; /* All of result of change must be printed */ - printrange(out, c, cm->c+st, cm->cl-st); - st = 0; + st1 = 0; /* All of result of change must be printed */ + printrange(out, c, cm->c+st1, cm->cl-st1); + st1 = 0; } fputs(words?"--->>>":">>>>>>>\n", out); m = cm; - if (m->in_conflict && m->hi >= m->al) { - assert(m->type == Unchanged); + if (m->in_conflict && m->type == Unchanged + && m->hi >= m->al) { printrange(out, a, m->a+m->lo, m->hi-m->lo); m++; } diff --git a/wiggle.h b/wiggle.h index 73fe809..42e9297 100644 --- a/wiggle.h +++ b/wiggle.h @@ -94,8 +94,9 @@ struct merge { int al, bl, cl; /* length of ranges */ int c1, c2; /* this or next commonsequence */ int in_conflict; - int lo,hi; /* region of an Unchanged that is not involved in a conflict - * These are distances from start of the section, not + int lo,hi; /* region of a Changed or Unchanged that is not involved + * in a conflict. + * These are distances from start of the "before" section, not * indexes into any file */ -- 2.39.5