From owner-freebsd-hackers Thu Jul 29 7:26:14 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from janus.syracuse.net (janus.syracuse.net [205.232.47.15]) by hub.freebsd.org (Postfix) with ESMTP id 2C82414E4E; Thu, 29 Jul 1999 07:26:10 -0700 (PDT) (envelope-from green@FreeBSD.org) Received: from localhost (green@localhost) by janus.syracuse.net (8.9.2/8.8.7) with ESMTP id KAA13939; Thu, 29 Jul 1999 10:25:31 -0400 (EDT) X-Authentication-Warning: janus.syracuse.net: green owned process doing -bs Date: Thu, 29 Jul 1999 10:25:31 -0400 (EDT) From: "Brian F. Feldman" X-Sender: green@janus.syracuse.net To: Sheldon Hearn Cc: Thomas David Rivers , freebsd-hackers@FreeBSD.org, jmz@FreeBSD.org Subject: Re: interesting bug in /usr/bin/cmp In-Reply-To: <43575.933246010@axl.noc.iafrica.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, 29 Jul 1999, Sheldon Hearn wrote: > > > On Thu, 29 Jul 1999 00:52:27 -0400, "Brian F. Feldman" wrote: > > > If noone has any objections, I will commit this and MFC it in a week or so. > > > > --- src/usr.bin/cmp/regular.c.orig Thu Jul 29 00:43:50 1999 > > +++ src/usr.bin/cmp/regular.c Thu Jul 29 00:44:54 1999 > > |--- src/usr.bin/cmp/regular.c.orig Thu Jul 29 00:43:50 1999 > |+++ src/usr.bin/cmp/regular.c Thu Jul 29 00:44:54 1999 > -------------------------- > Patching file regular.c using Plan A... > Hunk #1 succeeded at 57. > Hunk #2 failed at 76. > 1 out of 2 hunks failed--saving rejects to regular.c.rej > Hmm... Ignoring the trailing garbage. > done > > What's up? :-) > I have a better version. It's much more proper. Index: src/usr.bin/cmp/regular.c =================================================================== RCS file: /home/ncvs/src/usr.bin/cmp/regular.c,v retrieving revision 1.6 diff -u -r1.6 regular.c --- regular.c 1999/04/25 22:37:57 1.6 +++ regular.c 1999/07/29 14:20:23 @@ -60,6 +60,7 @@ off_t byte, length, line; int dfound; off_t pagemask, off1, off2; + size_t pagesize; if (sflag && len1 != len2) exit(1); @@ -71,7 +72,8 @@ eofmsg(file2); len2 -= skip2; - pagemask = (off_t)getpagesize() - 1; + pagesize = getpagesize(); + pagemask = (off_t)pagesize - 1; off1 = ROUNDPAGE(skip1); off2 = ROUNDPAGE(skip2); @@ -79,15 +81,15 @@ if (length > SIZE_T_MAX) return (c_special(fd1, file1, skip1, fd2, file2, skip2)); - if ((p1 = (u_char *)mmap(NULL, - (size_t)length, PROT_READ, MAP_SHARED, fd1, off1)) == (u_char *)MAP_FAILED) + if ((p1 = (u_char *)mmap(NULL, (size_t)len1 + skip1 % pagesize, + PROT_READ, MAP_SHARED, fd1, off1)) == (u_char *)MAP_FAILED) err(ERR_EXIT, "%s", file1); - madvise(p1, length, MADV_SEQUENTIAL); - if ((p2 = (u_char *)mmap(NULL, - (size_t)length, PROT_READ, MAP_SHARED, fd2, off2)) == (u_char *)MAP_FAILED) + madvise(p1, len1 + skip1 % pagesize, MADV_SEQUENTIAL); + if ((p2 = (u_char *)mmap(NULL, (size_t)len2 + skip2 % pagesize, + PROT_READ, MAP_SHARED, fd2, off2)) == (u_char *)MAP_FAILED) err(ERR_EXIT, "%s", file2); - madvise(p2, length, MADV_SEQUENTIAL); + madvise(p2, len2 + skip2 % pagesize, MADV_SEQUENTIAL); dfound = 0; p1 += skip1 - off1; > Ciao, > Sheldon. > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > Brian Fundakowski Feldman _ __ ___ ____ ___ ___ ___ green@FreeBSD.org _ __ ___ | _ ) __| \ FreeBSD: The Power to Serve! _ __ | _ \._ \ |) | http://www.FreeBSD.org/ _ |___/___/___/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message