From owner-svn-src-head@freebsd.org Fri Jul 27 05:21:21 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 106581060FFB; Fri, 27 Jul 2018 05:21:21 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BAEB384F59; Fri, 27 Jul 2018 05:21:20 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9C859139C4; Fri, 27 Jul 2018 05:21:20 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6R5LKSh010566; Fri, 27 Jul 2018 05:21:20 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6R5LKQW010565; Fri, 27 Jul 2018 05:21:20 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201807270521.w6R5LKQW010565@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Fri, 27 Jul 2018 05:21:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336754 - in head/usr.bin/diff: . tests X-SVN-Group: head X-SVN-Commit-Author: delphij X-SVN-Commit-Paths: in head/usr.bin/diff: . tests X-SVN-Commit-Revision: 336754 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jul 2018 05:21:21 -0000 Author: delphij Date: Fri Jul 27 05:21:20 2018 New Revision: 336754 URL: https://svnweb.freebsd.org/changeset/base/336754 Log: Improve --strip-trailing-cr handling: - Advance ctold for f1 and ctnew for f2 - ungetc() if the character is unexpected - Don't break early when we hit the combination on one side PR: 230049 Reported by: maskray Reviewed by: bapt, maskray MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D16451 Modified: head/usr.bin/diff/diffreg.c head/usr.bin/diff/tests/diff_test.sh Modified: head/usr.bin/diff/diffreg.c ============================================================================== --- head/usr.bin/diff/diffreg.c Fri Jul 27 01:20:34 2018 (r336753) +++ head/usr.bin/diff/diffreg.c Fri Jul 27 05:21:20 2018 (r336754) @@ -720,19 +720,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: head/usr.bin/diff/tests/diff_test.sh ============================================================================== --- head/usr.bin/diff/tests/diff_test.sh Fri Jul 27 01:20:34 2018 (r336753) +++ head/usr.bin/diff/tests/diff_test.sh Fri Jul 27 05:21:20 2018 (r336754) @@ -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 }