Fix various regressions
These are various issues that I identified while bisecting/testing various issues with latest kdiff3 versions, in particular crashes and spurious empty lines / failures merging trailing newlines. Some of them have been fixed recently but the remaining fixes still make sense to be pulled.