[575] in Athena Bugs

home help back first fref pref prev next nref lref last post

[comp.unix.wizards: Bug in 'grep']

daemon@ATHENA.MIT.EDU (Ken Raeburn)
Mon Aug 1 19:57:22 1988

Date: Mon, 1 Aug 88 19:56:44 EDT
From: Ken Raeburn <raeburn@ATHENA.MIT.EDU>
To: bugs@ATHENA.MIT.EDU

Check for this one too....

------- Forwarded Message

From: <raeburn@ATHENA.MIT.EDU>
Date: Sun, 17 Jul 88 16:52:50 EDT
To: raeburn@ATHENA.MIT.EDU

Path: bloom-beacon!husc6!purdue!umd5!cvl!arensb
From: arensb@cvl.umd.edu (Andrew Arensburger)
Newsgroups: comp.unix.wizards
Subject: Bug in 'grep'
Message-ID: <2984@cvl.umd.edu>
Date: 13 Jul 88 16:45:01 GMT
Reply-To: arensb@lemuria.UUCP (Andrew Arensburger)
Organization: Center for Automation Research, Univ. of Md.
Lines: 52


	There is a bug in 'grep': if the input file does not end with a
newline, and your pattern is in the last line, 'grep' will not find it.
The routine 'execute', which reads in lines from the input file and compares
them to the pattern should be changed from


execute(file)
char *file;
{
	register char *p1, *p2;
	register c;

	[...]

	for (;;) {
		lnum++;
		p1 = linebuf;
		while ((c = getchar()) != '\n') {
			if (c == EOF) {
				[...]
				return;
			}
		[...]


to


execute(file)
char *file;
{
	register char *p1, *p2;
	register c;
	char eof;			/* 'end-of-file' flag */

	[...]

	for (eof = 0; !eof;) {		/* While not end of file */
		lnum++;
		p1 = linebuf;
		while ((c = getchar()) != '\n') {
			if (c == EOF) {
				[...]
				eof = 1;
				break;
			}
		[...]

which neatly circumvents the problem.

					/AA/

------- End Forwarded Message

home help back first fref pref prev next nref lref last post