The branch main has been updated by pstef:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=7f7b03f3897f0196e3cc7a3b71c7359cc206ba61

commit 7f7b03f3897f0196e3cc7a3b71c7359cc206ba61
Author:     Piotr Pawel Stefaniak <ps...@freebsd.org>
AuthorDate: 2021-08-20 21:35:24 +0000
Commit:     Piotr Pawel Stefaniak <ps...@freebsd.org>
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));
_______________________________________________
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"

Reply via email to