Author: delphij
Date: Mon Sep  3 06:36:28 2018
New Revision: 338439
URL: https://svnweb.freebsd.org/changeset/base/338439

Log:
  MFC r336754: Improve --strip-trailing-cr handling.

Modified:
  stable/11/usr.bin/diff/diffreg.c
  stable/11/usr.bin/diff/tests/diff_test.sh
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/diff/diffreg.c
==============================================================================
--- stable/11/usr.bin/diff/diffreg.c    Mon Sep  3 03:23:09 2018        
(r338438)
+++ stable/11/usr.bin/diff/diffreg.c    Mon Sep  3 06:36:28 2018        
(r338439)
@@ -792,19 +792,22 @@ check(FILE *f1, FILE *f2, int flags)
                                }
                                ctold++;
                                ctnew++;
-                               if (flags & D_STRIPCR) {
+                               if (flags & D_STRIPCR && (c == '\r' || d == 
'\r')) {
                                        if (c == '\r') {
                                                if ((c = getc(f1)) == '\n') {
-                                                       ctnew++;
-                                                       break;
+                                                       ctold++;
+                                               } else {
+                                                       ungetc(c, f1);
                                                }
                                        }
                                        if (d == '\r') {
                                                if ((d = getc(f2)) == '\n') {
-                                                       ctold++;
-                                                       break;
+                                                       ctnew++;
+                                               } else {
+                                                       ungetc(d, f2);
                                                }
                                        }
+                                       break;
                                }
                                if ((flags & D_FOLDBLANKS) && isspace(c) &&
                                    isspace(d)) {

Modified: stable/11/usr.bin/diff/tests/diff_test.sh
==============================================================================
--- stable/11/usr.bin/diff/tests/diff_test.sh   Mon Sep  3 03:23:09 2018        
(r338438)
+++ stable/11/usr.bin/diff/tests/diff_test.sh   Mon Sep  3 06:36:28 2018        
(r338439)
@@ -8,6 +8,7 @@ atf_test_case ifdef
 atf_test_case group_format
 atf_test_case side_by_side
 atf_test_case brief_format
+atf_test_case b230049
 
 simple_body()
 {
@@ -52,6 +53,15 @@ unified_body()
                diff -u9999 -L input_c1.in -L input_c2.in 
"$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
 }
 
+b230049_body()
+{
+       printf 'a\nb\r\nc\n' > b230049_a.in
+       printf 'a\r\nb\r\nc\r\n' > b230049_b.in
+       atf_check -o empty -s eq:0 \
+               diff -up --strip-trailing-cr -L b230049_a.in -L b230049_b.in \
+                   b230049_a.in b230049_b.in
+}
+
 header_body()
 {
        export TZ=UTC
@@ -150,4 +160,5 @@ atf_init_test_cases()
        atf_add_test_case group_format
        atf_add_test_case side_by_side
        atf_add_test_case brief_format
+       atf_add_test_case b230049
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to