0a6a4f
commit 76e775847f4954b63dc72afe34d9d921c6688b31
0a6a4f
Author: Andreas Gruenbacher <agruen@gnu.org>
0a6a4f
Date:   Tue Jul 16 01:16:28 2019 +0200
0a6a4f
0a6a4f
    Fix failed assertion 'outstate->after_newline'
0a6a4f
    
0a6a4f
    The assertion triggers when the -o FILE option is used, more than one output
0a6a4f
    file is written into FILE, and one of those files (except the last one) ends in
0a6a4f
    the middle of a line.
0a6a4f
    * src/patch.c (main): Fix the case described above.
0a6a4f
0a6a4f
diff --git a/src/patch.c b/src/patch.c
0a6a4f
index 02fd982..3794319 100644
0a6a4f
--- a/src/patch.c
0a6a4f
+++ b/src/patch.c
0a6a4f
@@ -369,6 +369,13 @@ main (int argc, char **argv)
0a6a4f
 	    /* outstate.ofp now owns the file descriptor */
0a6a4f
 	    outfd = -1;
0a6a4f
 	  }
0a6a4f
+	else
0a6a4f
+	  {
0a6a4f
+	    /* When writing to a single output file (-o FILE), always pretend
0a6a4f
+	       that the output file ends in a newline.  Otherwise, when another
0a6a4f
+	       file is written to the same output file, apply_hunk will fail.  */
0a6a4f
+	    outstate.after_newline = true;
0a6a4f
+	  }
0a6a4f
 
0a6a4f
 	/* find out where all the lines are */
0a6a4f
 	if (!skip_rest_of_patch) {