From nobody Mon Dec 09 19:45:20 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Y6XQT1ddPz5gjVv; Mon, 09 Dec 2024 19:45:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y6XQT10jkz44PB; Mon, 9 Dec 2024 19:45:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733773521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=k3n0zvOcz2SxE3f18lxHvlv8wJaeYrfdx9HZRYt/H4M=; b=Niq7Xfsyz9e8qixbPefNudB1vYA2ameBSPGeITFdy859JC+UtQbITguxguXOkDGbsQt4w/ tVRFFiginL3Gd/2V6jAdI1OffefhqWJCbehxsookL2GbFXTccZTDa4t7B1nQcf6ENeErok tsZDX59MS/uRtuo9xfS9fl1PY3yIzN/dfDWjwc70a+RnXTqH8I3b6N3DLrIGgNC5jgEAeC xfLX/+b6pP8gcI3E9ohOr009uKeFDFNxQI5KSJo8NselE0y7Z4IIFHGCkpSsEqyluo1Fjs Ydcr9INAJ78660CX2sVN8ANDiRKyiqlUA1P3Bd5RcIZQ+Unlv6RMw0wKNCJ/bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733773521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=k3n0zvOcz2SxE3f18lxHvlv8wJaeYrfdx9HZRYt/H4M=; b=I/8AuKI81tAJKl1iiutVTKvlDk6wdmExTM6zrg/naPvyN+jLkGX3ZvOoeHIWems4GNEkN2 YO7N/aSsvPij0HTBTkgbyHtCOsogb10/4+5noNldJnBCBsOfPGVDnVIHgREAJSqjiI0tq3 tJtUZJohn8SEFemui9pv9FIlap3OdgPaITE7aI07MNCTYzTomVHTl06iSwOKjICbwZwrmj VR3p9lWYOBAAjWTNVX3n51YXjttsj0SEUXwPMCwasRwc/4KZsAiphQneiq7leactOSTIDm bmsW3O5qC3lPMcs7/kWU3PP0qic8ogiV8w8Wq02eyU1h9ESZYQMqdugsHf6P2w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733773521; a=rsa-sha256; cv=none; b=lo1ADNI4IQt6dWFoGx568T0rFZi/o1xt2TDvii1iEUyRBQK9KuX2GAA0xVRY33oB92Vb5F FF+9saFrN5qaS2aCs0n8Z5kMQFg81xcbEyF/gf8lcEfH4XMEZvARLPBY/i3BwxkWBC224r 6+0Q2MYLP0f8o4r9NjUgnoxO7WAuV+YJ6q+E0MR/iM6mfsdX+fLx4eeDz/N6Epl+VZZbCn 9ZMOIjBQ3bBZdfzpbHMm1AF9COexnRFPDsY4fubdAI+70PpmDpdQLfFhbyX7+A5gGOVrZJ TBhYvKdCi41+5Y8svkNm+ANPM7kXBSTi7fiofkJd/oqvq61+OK9Ti/jhdTzvoA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Y6XQT0bDBzrs6; Mon, 9 Dec 2024 19:45:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4B9JjKgP009484; Mon, 9 Dec 2024 19:45:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B9JjKDi009481; Mon, 9 Dec 2024 19:45:20 GMT (envelope-from git) Date: Mon, 9 Dec 2024 19:45:20 GMT Message-Id: <202412091945.4B9JjKDi009481@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: c3f8900e6969 - main - uniq: Fix off-by-one bug in -cD case. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c3f8900e696998c410dc16f9bd9d45c24c413e6b Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=c3f8900e696998c410dc16f9bd9d45c24c413e6b commit c3f8900e696998c410dc16f9bd9d45c24c413e6b Author: Dag-Erling Smørgrav AuthorDate: 2024-12-09 19:44:46 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-12-09 19:44:46 +0000 uniq: Fix off-by-one bug in -cD case. When printing only duplicated lines, the first line of each set is not printed until we encounter the second. When that happens, we need to increment the repetition count between printing the first and the second line, so that if we are also printing counts, we don't print the same (pre-increment) count twice. MFC after: 1 week PR: 275764 Reported by: Yu-Sheng Ma Submitted by: Daniel Tameling (original patch) Sponsored by: Klara, Inc. Reviewed by: tamelingdaniel_gmail.com, asomers, emaste Differential Revision: https://reviews.freebsd.org/D48000 --- usr.bin/uniq/tests/uniq_test.sh | 20 ++++++++++++++++++++ usr.bin/uniq/uniq.c | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/usr.bin/uniq/tests/uniq_test.sh b/usr.bin/uniq/tests/uniq_test.sh index fa37c1959a77..fc143632bdd2 100755 --- a/usr.bin/uniq/tests/uniq_test.sh +++ b/usr.bin/uniq/tests/uniq_test.sh @@ -80,6 +80,25 @@ all_repeated_body() { atf_check_uniq --all-repeated=separate } +atf_test_case count_all_repeated +count_all_repeated_head() { + atf_set descr "count and print every instance of repeated lines" +} +count_all_repeated_body() { + printf "a\na\nb\na\na\n" >input + printf " 1 a\n 2 a\n 1 a\n 2 a\n" >expected + atf_check_uniq -D -c + atf_check_uniq -Dnone -c + atf_check_uniq -cD + atf_check_uniq -cDnone + atf_check_uniq -c -D + atf_check_uniq -c -Dnone + atf_check_uniq --all-repeated --count + atf_check_uniq --all-repeated=none --count + atf_check_uniq --count --all-repeated + atf_check_uniq --count --all-repeated=none +} + atf_test_case skip_fields skip_fields_head() { atf_set descr "skip fields" @@ -196,6 +215,7 @@ atf_init_test_cases() atf_add_test_case repeated atf_add_test_case count_repeated atf_add_test_case all_repeated + atf_add_test_case count_all_repeated atf_add_test_case skip_fields atf_add_test_case skip_fields_tab atf_add_test_case ignore_case diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c index 1c022e633cf3..0650ec2e2137 100644 --- a/usr.bin/uniq/uniq.c +++ b/usr.bin/uniq/uniq.c @@ -225,12 +225,13 @@ main (int argc, char *argv[]) fputc('\n', ofp); show(ofp, prevline); } - show(ofp, thisline); } else if (dflag && !cflag) { if (repeats == 0) show(ofp, prevline); } ++repeats; + if (Dflag) + show(ofp, thisline); } } if (ferror(ifp))