From nobody Sun Dec 3 17:35:03 2023 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 4Sjv7r0tm6z5383t; Sun, 3 Dec 2023 17:35:04 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sjv7r0NvYz3KRm; Sun, 3 Dec 2023 17:35:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701624904; 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=M07aUcBIDBHt/0URJfcXjezd4QasaDE00iEMgGorS4U=; b=h5r3r53q8efwhR+uL9BskUEGLG6KjVuLJZxVhnkgtthUrVBFG5l+U5lLJe5GmtYHcqQ6cn 1uKSg05m3Fl/6xyCMC4gczJMaRCzEcowzZnxtp9HJxHV2gqM1ReBvFKaVguJ6L7OWMAJ9/ LcEseu4jkLABGSX0BhPX5lFMf5s8CmhVRKDovGTAG7GevDb7F7Co5y61lYOzXU8Xa/tDvM fmG5AlhuVrlI4CyQ9EwFpYyOdi5Vd19aSQmRUJV2jArv5YIzILKusMHwar7O49Ju2UixZX xko0zHDVkFcz6UmrU5ZamLTCIwCXPFhhD2O2a9JCda+2/xLHxYgjUeiAwG0xag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701624904; 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=M07aUcBIDBHt/0URJfcXjezd4QasaDE00iEMgGorS4U=; b=MsYxGSyQ7QeiXaamsROuF7wdy73sINE07aYht66d4Cf9xx7NdBg0NEERSl4XaR6fKrf6ZX OOksO7ScIl0tdEdx74/stWKYbi7kftkPrMiDhO9uH/yz9p9EU3OfE+8ENq0zyXZXOWAZd1 89gFeKWhJTogd2D+eIIja83fH5qNYGatYKHHmlrP5N8zF9rEGQbgp9xi0/KmGKEGF51Kzw Y+xlgTi8w7UwwOiFvDpoibhz3liPG6Z9F7e6e7a3FZBJB2HEzEpXS5Ax8G1E3sLUjJXwWo OiwbrNIi9FAOSpEAh6cBdO5imJv592ujUbNkrD1K0QCtGi3wmrkZQOM/bzSUhw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701624904; a=rsa-sha256; cv=none; b=xqLilwfwyAaLZc0SG77vveYFuNtxGnJSPLHKVc1CirvV9FKMycBltMx+6U8o7wPkDGcTo+ qaR4ai85qTb71tSojO/fpX9MnyNBiRM4qyTTdYA7OhyjjiKuddEn7lbtG0HsAPu3SOuKkI 6VabBJ+h1upOu3s+xQPQHxz4V6ZojHKv+R1zVdlhghfaKyPs4K0Q0uK762GyHoF9VsUbHk If1ItIbka7NtWLhtOEVvDCrscKIAY0ASTOBSktLU2E4p3MobxctdUX6UgRXFjYW2+gZ+0D 8PAv35yqzJ0cFiEE+4vwfcgpONEqfr5mWIkYMOwizmsDpAfNIhOHVb1Fhsbr1g== 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 4Sjv7q6Y7dz17GK; Sun, 3 Dec 2023 17:35:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3B3HZ3hN004779; Sun, 3 Dec 2023 17:35:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3B3HZ3rh004776; Sun, 3 Dec 2023 17:35:03 GMT (envelope-from git) Date: Sun, 3 Dec 2023 17:35:03 GMT Message-Id: <202312031735.3B3HZ3rh004776@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Pedro F. Giffuni" Subject: git: 7e8afbb6d605 - main - patch: fix locate_hunk in empty files 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pfg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7e8afbb6d605006d7cb867362b225d21c4f5ae57 Auto-Submitted: auto-generated The branch main has been updated by pfg: URL: https://cgit.FreeBSD.org/src/commit/?id=7e8afbb6d605006d7cb867362b225d21c4f5ae57 commit 7e8afbb6d605006d7cb867362b225d21c4f5ae57 Author: Pedro F. Giffuni AuthorDate: 2023-12-03 17:33:03 +0000 Commit: Pedro F. Giffuni CommitDate: 2023-12-03 17:33:03 +0000 patch: fix locate_hunk in empty files if `first_guess' is zero then main() assumes that locate_hunk has failed and aborts the patch operation. Instead, make sure to return 1 (the line number) so that the patch operation can continue. Issue originally found by Neels Hofmeyr in the regress suite of the diff implementation for got, where the tests assume that applying a diff with `patch' and then again with `patch -R' yields back the original file. Obtained from: OpenBSD (CVS patch.c,v 1.71) --- usr.bin/patch/patch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index ecaf799fe9b6..403189bc92b1 100644 --- a/usr.bin/patch/patch.c +++ b/usr.bin/patch/patch.c @@ -717,6 +717,8 @@ locate_hunk(LINENUM fuzz) || diff_type == UNI_DIFF)) { say("Empty context always matches.\n"); } + if (first_guess == 0) /* empty file */ + return 1; return (first_guess); } if (max_neg_offset >= first_guess) /* do not try lines < 0 */