From nobody Fri Feb 13 20:19:31 2026 X-Original-To: dev-commits-src-main@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 4fCNmz6F2gz6RlPj for ; Fri, 13 Feb 2026 20:19:31 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fCNmz5HcMz3Mpw for ; Fri, 13 Feb 2026 20:19:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1771013971; 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=u+jct1HMPilPlcaPNRYv0bSeK6C4KoMchRuCQeOLdJM=; b=NwfCZyf+8tHzkC7YJuvo5FBeZ6iq5WwMzVzU4W3Lw2bH5IyX05In9FNcHGpOIJnTv6i/Qv 4hB7pyZvycZAPkd8LVlPjx8ZdNfdYVanqqCwmDRUPdiaEgAuqsyyAmrZtT9XhTIRQ1ezL+ i8hgaG7pDE1aVV++b4nrIwymYaYoqUD0UveFNOp8dxrIIrr14IoDdjU7+iQAx12s0oCFad +EIvTYvZVGrDWUTkxB0U9wvDPvsZ/LhEU9ydSyrnstsGboTGMThWOXGkCncG6afrxcj6MC yJdnMRjmbljaBKbXKkW3rbQib3RsJrrVPDmFv64hKFz0+rCcwCqaYP46yoLB3w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1771013971; a=rsa-sha256; cv=none; b=v6geYo5VsdjPMgVs2eW5WafSj4aL9tWu/JUUFJKF9lk6r0YMCbif1kY16yAc1B1Nl9u+/W Nw0EbR0mY06LthvlAQqQqaSKGvqEnKnUzjDiWL+Ah/TILWbk1CY4kD6iYXkzXMKB/DMZ1A 3GkoFITsY3KVBRGHqJqiX47J0fUT5LnxC8ZDm9YvazokA1CBS94qvc4IOKDLdfRIRJbE+A x7tW8JpO+gDkRwyoyAh3ao40bHHI696rBKwpmb8YTb6vGgwaDkywE3ZFE71b/Iw2Wizqqf 3AEfQFZIxWDMgh9qbJ9HFxvN6M+NHQQIsQbzcpMAW5Z30XVqZzdZv9pXamK2ig== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1771013971; 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=u+jct1HMPilPlcaPNRYv0bSeK6C4KoMchRuCQeOLdJM=; b=qf/flq0LRb/SiJII+kGvX+EEb5YJCoJjtuxRrWjSi6kG5CkZmDeh4OHN5MIinigbljovaC eZCCQMIWpkP+H1CEE5frzfEy1LSJTKkIdF4ca80cOJcNxU7ojDfKy+js+tIUt9+LzS2YAW om3Sq7DKY22ozOWbFjfOdxQgPRL2GtgpGNPU764zsTTWPPAa9SXLedY1NcW8BcB7qbbBmV XeZQZqJTJNlbjCoKl+Bl1xHm9FtZE2Ew4gnTDeA1hgk6c5V9kUx1qh9E9SGMFR+FP2ZSqx v0AmcGRhNUVtILBfhVeqbBIEsLuY8bxwI8aa0xQomRIfsoBBB8/bM8MJV+TSCg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fCNmz4c1hzcm0 for ; Fri, 13 Feb 2026 20:19:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 44d0a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 13 Feb 2026 20:19:31 +0000 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=B8rg?=rav Subject: git: 790f1d1cc5fa - main - diff: Tweak range of -C and -U arguments List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 790f1d1cc5fa892ba59fd7f239b22064c8ab14c7 Auto-Submitted: auto-generated Date: Fri, 13 Feb 2026 20:19:31 +0000 Message-Id: <698f8753.44d0a.36173b26@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=790f1d1cc5fa892ba59fd7f239b22064c8ab14c7 commit 790f1d1cc5fa892ba59fd7f239b22064c8ab14c7 Author: Dag-Erling Smørgrav AuthorDate: 2026-02-13 20:18:24 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-02-13 20:19:16 +0000 diff: Tweak range of -C and -U arguments POSIX uses the terms “positive decimal integer” for -C and “non-negative decimal integer” for -U, which translates into lower bounds of 1 for -C and 0 for -U. POSIX does not specify a minimum upper bound for either mode, but as of 5fc739eb5949 both our backends support context sizes up to and including INT_MAX, so use that. Having had the opportunity to consult the Unix System Test Suite, the diff test cases found therein happen to precisely match these bounds. While here, switch to using strtonum() to parse numerical arguments, and try to be more consistent in how we report usage errors. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55261 --- usr.bin/diff/diff.c | 44 +++++++++++++++++------------ usr.bin/diff/tests/diff_test.sh | 62 +++++++++++++++++++++++++---------------- 2 files changed, 64 insertions(+), 42 deletions(-) diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index 9bf3f2ad79eb..b5fa12268bac 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -137,10 +137,9 @@ static bool do_color(void); int main(int argc, char **argv) { - const char *errstr = NULL; - char *ep, **oargv; - long l; - int ch, dflags, lastch, gotstdin, prevoptind, newarg; + const char *errstr; + char **oargv; + int ch, dflags, lastch, gotstdin, prevoptind, newarg; oargv = argv; gotstdin = 0; @@ -177,7 +176,7 @@ main(int argc, char **argv) } if (diff_algorithm == D_DIFFNONE) { - printf("unknown algorithm: %s\n", optarg); + warnx("unknown algorithm: %s", optarg); usage(); } break; @@ -194,10 +193,13 @@ main(int argc, char **argv) cflag = true; diff_format = D_CONTEXT; if (optarg != NULL) { - l = strtol(optarg, &ep, 10); - if (*ep != '\0' || l < 0 || l >= INT_MAX) + diff_context = (int) strtonum(optarg, + 1, INT_MAX, &errstr); + if (errstr != NULL) { + warnx("context size is %s: %s", + errstr, optarg); usage(); - diff_context = (int)l; + } } break; case 'd': @@ -294,10 +296,13 @@ main(int argc, char **argv) conflicting_format(); diff_format = D_UNIFIED; if (optarg != NULL) { - l = strtol(optarg, &ep, 10); - if (*ep != '\0' || l < 0 || l >= INT_MAX) + diff_context = (int) strtonum(optarg, + 0, INT_MAX, &errstr); + if (errstr != NULL) { + warnx("context size is %s: %s", + errstr, optarg); usage(); - diff_context = (int)l; + } } break; case 'w': @@ -305,8 +310,8 @@ main(int argc, char **argv) break; case 'W': width = (int) strtonum(optarg, 1, INT_MAX, &errstr); - if (errstr) { - warnx("Invalid argument for width"); + if (errstr != NULL) { + warnx("width is %s: %s", errstr, optarg); usage(); } break; @@ -346,8 +351,8 @@ main(int argc, char **argv) break; case OPT_TSIZE: tabsize = (int) strtonum(optarg, 1, INT_MAX, &errstr); - if (errstr) { - warnx("Invalid argument for tabsize"); + if (errstr != NULL) { + warnx("tabsize is %s: %s", errstr, optarg); usage(); } break; @@ -364,9 +369,12 @@ main(int argc, char **argv) colorflag = COLORFLAG_ALWAYS; else if (strncmp(optarg, "never", 5) == 0) colorflag = COLORFLAG_NEVER; - else - errx(2, "unsupported --color value '%s' (must be always, auto, or never)", - optarg); + else { + warnx("unsupported --color value " + "(must be always, auto, or never): " + "%s", optarg); + usage(); + } break; case OPT_NO_DEREFERENCE: noderef = true; diff --git a/usr.bin/diff/tests/diff_test.sh b/usr.bin/diff/tests/diff_test.sh index 0d3acf50edf9..3afd12355a80 100755 --- a/usr.bin/diff/tests/diff_test.sh +++ b/usr.bin/diff/tests/diff_test.sh @@ -24,8 +24,8 @@ atf_test_case functionname atf_test_case noderef atf_test_case ignorecase atf_test_case dirloop -atf_test_case bigc -atf_test_case bigu +atf_test_case crange +atf_test_case urange atf_test_case prleak atf_test_case same @@ -389,34 +389,48 @@ dirloop_body() atf_check diff -r a b } -bigc_head() +crange_head() { - atf_set "descr" "Context diff with very large context" + atf_set "descr" "Context diff context length range" } -bigc_body() +crange_body() { - echo $'x\na\ny' >a - echo $'x\nb\ny' >b - atf_check -s exit:2 -e ignore diff -C$(((1<<31)-1)) a b - atf_check -s exit:1 -o match:'--- 1,3 ---' \ - diff -C$(((1<<31)-2)) a b - atf_check -s exit:1 -o match:'--- 1,3 ---' \ - diff -Astone -C$(((1<<31)-2)) a b + echo $'x\nx\na\ny\ny' >a + echo $'x\nx\nb\ny\ny' >b + atf_check -s exit:2 -e match:'too small' \ + diff -C-1 a b + atf_check -s exit:2 -e match:'too small' \ + diff -C0 a b + atf_check -s exit:1 -o match:'--- 2,4 ---' \ + diff -C1 a b + atf_check -s exit:1 -o match:'--- 2,4 ---' \ + diff -Astone -C1 a b + atf_check -s exit:2 -e match:'too large' \ + diff -C$((1<<31)) a b + atf_check -s exit:1 -o match:'--- 1,5 ---' \ + diff -C$(((1<<31)-1)) a b + atf_check -s exit:1 -o match:'--- 1,5 ---' \ + diff -Astone -C$(((1<<31)-1)) a b } -bigu_head() +urange_head() { - atf_set "descr" "Unified diff with very large context" + atf_set "descr" "Unified diff context length range" } -bigu_body() +urange_body() { - echo $'x\na\ny' >a - echo $'x\nb\ny' >b - atf_check -s exit:2 -e ignore diff -U$(((1<<31)-1)) a b - atf_check -s exit:1 -o match:'^@@ -1,3 \+1,3 @@$' \ - diff -U$(((1<<31)-2)) a b - atf_check -s exit:1 -o match:'^@@ -1,3 \+1,3 @@$' \ - diff -Astone -U$(((1<<31)-2)) a b + echo $'x\nx\na\ny\ny' >a + echo $'x\nx\nb\ny\ny' >b + atf_check -s exit:2 -e match:'too small' \ + diff -U-1 a b + atf_check -s exit:1 -o match:'^@@ -3 \+3 @@$' \ + diff -U0 a b + atf_check -s exit:2 -e match:'too large' \ + diff -U$((1<<31)) a b + atf_check -s exit:1 -o match:'^@@ -1,5 \+1,5 @@$' \ + diff -U$(((1<<31)-1)) a b + atf_check -s exit:1 -o match:'^@@ -1,5 \+1,5 @@$' \ + diff -Astone -U$(((1<<31)-1)) a b } prleak_head() @@ -485,8 +499,8 @@ atf_init_test_cases() atf_add_test_case noderef atf_add_test_case ignorecase atf_add_test_case dirloop - atf_add_test_case bigc - atf_add_test_case bigu + atf_add_test_case crange + atf_add_test_case urange atf_add_test_case prleak atf_add_test_case same }