From owner-dev-commits-src-all@freebsd.org Mon Aug 23 05:07:24 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6097F663A84; Mon, 23 Aug 2021 05:07:24 +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 4GtKx80K4cz3pHr; Mon, 23 Aug 2021 05:07:24 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 DB15860E6; Mon, 23 Aug 2021 05:07:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17N57NW7023354; Mon, 23 Aug 2021 05:07:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17N57NPE023353; Mon, 23 Aug 2021 05:07:23 GMT (envelope-from git) Date: Mon, 23 Aug 2021 05:07:23 GMT Message-Id: <202108230507.17N57NPE023353@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: 7f7b03f3897f - main - diff3: sync with upstream MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pstef X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7f7b03f3897f0196e3cc7a3b71c7359cc206ba61 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Aug 2021 05:07:24 -0000 The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=7f7b03f3897f0196e3cc7a3b71c7359cc206ba61 commit 7f7b03f3897f0196e3cc7a3b71c7359cc206ba61 Author: Piotr Pawel Stefaniak AuthorDate: 2021-08-20 21:35:24 +0000 Commit: Piotr Pawel Stefaniak CommitDate: 2021-08-23 05:04:28 +0000 diff3: sync with upstream * replace realloc calls with reallocarray calls * fix merging of files that lack newlines Obtained from: OpenBSD --- usr.bin/diff3/diff3.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c index 03cd24283a13..80d4a202728f 100644 --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -459,6 +459,8 @@ duplicate(struct range *r1, struct range *r2) do { c = getc(fp[0]); d = getc(fp[1]); + if (c == -1 && d == -1) + break; if (c == -1 || d== -1) errx(EXIT_FAILURE, "logic error"); nchar++; @@ -528,10 +530,17 @@ edscript(int n) } fseek(fp[2], (long)de[n].new.from, SEEK_SET); for (k = de[n].new.to - de[n].new.from; k > 0; k-= j) { + size_t r; j = k > BUFSIZ ? BUFSIZ : k; - if (fread(block, 1, j, fp[2]) != j) + r = fread(block, 1, j, fp[2]); + if (r == 0) { + if (feof(fp[2])) + break; errx(2, "logic error"); - fwrite(block, 1, j, stdout); + } + if (r != j) + j = r; + (void)fwrite(block, 1, j, stdout); } if (!oflag || !overlap[n]) printf(".\n"); @@ -557,22 +566,22 @@ increase(void) newsz = szchanges == 0 ? 64 : 2 * szchanges; incr = newsz - szchanges; - p = realloc(d13, newsz * sizeof(struct diff)); + p = reallocarray(d13, newsz, sizeof(struct diff)); if (p == NULL) err(1, NULL); memset(p + szchanges, 0, incr * sizeof(struct diff)); d13 = p; - p = realloc(d23, newsz * sizeof(struct diff)); + p = reallocarray(d23, newsz, sizeof(struct diff)); if (p == NULL) err(1, NULL); memset(p + szchanges, 0, incr * sizeof(struct diff)); d23 = p; - p = realloc(de, newsz * sizeof(struct diff)); + p = reallocarray(de, newsz, sizeof(struct diff)); if (p == NULL) err(1, NULL); memset(p + szchanges, 0, incr * sizeof(struct diff)); de = p; - q = realloc(overlap, newsz * sizeof(char)); + q = reallocarray(overlap, newsz, sizeof(char)); if (q == NULL) err(1, NULL); memset(q + szchanges, 0, incr * sizeof(char));