vpatch: fix various reference errors found by valgrind.

We sometimes fall of the end, or the start, of various arrays,
or use variables we haven't initialised.

Reported-by: Paul Wise <pabs3@bonedaddy.net>
Signed-off-by: NeilBrown <neilb@suse.de>
vpatch: allow relevant signals to cause a core-dump.

We catch SIGBUS and SIGSEGV so the terminal can be reset.
But that means we don't see a core dump if there should be one.

So for those signals, clear the signal handler after reseting
the terminal, and return.  Then the core will be dumped.

Reported-by: Paul Wise <pabs3@bonedaddy.net>
vpatch: fix another access-beyond-array

This was found by valgrind as well: prev_melmnt needs to check
'type' just like next_melmnt does.

This  revealed an infinite loop because we have a 'hi' value that
was wrong but being trusted.

Signed-off-by: NeilBrown <neilb@suse.de>
merge: remove useless context at the start of a conflict.

There are two fixes here.

The first allows the newline at the end of an unchanged region to be
the 'first' newline found so that if there are several others to
provide backup, it will be used.

The second allows the start-of-file to be strong enough context to
not require three full lines of explicit context.

Then we change a lot of the self-tests to match.  In each case the
result is a clear improvement.

Signed-off-by: NeilBrown <neilb@suse.de>
merge: remove useless context from the end of a conflict.

If we are close to the end-of-file, then don't expect
too many unchanged lines.
And allow zero lines of context in the merge if  it is unchanged out
side the merge.

Update various tests to match - all clear improvements.

Signed-off-by: NeilBrown <neilb@suse.de>
bestmatch: improve poor matches.

If the bestmatch doens't include all of the lines in a hunk, try to
find matches between the unmatch parts of the hunk, and surrounding
text in the original.

This is particularly useful when some of the context is just blank
lines.  The best-match algorithm might ignore blank lines because they
aren't big enough to justify much distance from the rest of the match.

This makes tests/linux/raid1-A/merge a lot nicer.

Signed-off-by: NeilBrown <neilb@suse.de>
merge: remove some meaningless AlreadyApplied

Finding an AlreadyApplied amid Conflicts and Extraneous etc is
unlikely to be helpful.  So don't do it.

Signed-off-by: NeilBrown <neilb@suse.de>
Add "make valgrind"

This runs the test suite under valgrind and complains if any
errors are detected.

Signed-off-by: NeilBrown <neilb@suse.de>
Add valgrind testing of parts of vpatch.

With --self-test, browsing a simple merge will simply
display at every line.
"make vtest" will run this for every merge in the test suite
and use valgrind to look for problems.

Signed-off-by: NeilBrown <neilb@suse.de>