Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Jul 1999 10:25:31 -0400 (EDT)
From:      "Brian F. Feldman" <green@FreeBSD.org>
To:        Sheldon Hearn <sheldonh@uunet.co.za>
Cc:        Thomas David Rivers <rivers@dignus.com>, freebsd-hackers@FreeBSD.org, jmz@FreeBSD.org
Subject:   Re: interesting bug in /usr/bin/cmp 
Message-ID:  <Pine.BSF.4.10.9907291023470.13541-100000@janus.syracuse.net>
In-Reply-To: <43575.933246010@axl.noc.iafrica.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.9907291023470.13541-100000>