Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Dec 2008 04:52:24 GMT
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 155260 for review
Message-ID:  <200812250452.mBP4qOUI055868@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=155260

Change 155260 by gabor@gabor_server on 2008/12/25 04:51:32

	- Fix file handling bugs

Affected files ...

.. //depot/projects/soc2008/gabor_textproc/grep/file.c#34 edit
.. //depot/projects/soc2008/gabor_textproc/grep/util.c#77 edit

Differences ...

==== //depot/projects/soc2008/gabor_textproc/grep/file.c#34 (text+ko) ====

@@ -118,7 +118,7 @@
 grep_fgetln(struct file *f, size_t *len)
 {
 	int		 i = 0;
-	char		 ch;
+	int		 ch = 0;
 
 	/* Fill in the buffer if it is empty. */
 	if (binbufptr == NULL) {
@@ -149,11 +149,16 @@
 			lnbuflen *= 2;
 			lnbuf = grep_realloc(lnbuf, ++lnbuflen);
 		}
-		if (ch == '\n')
+		if (ch == '\n') {
+			lnbuf[i] = '\0';
+			break;
+		}
+		if (ch != EOF)
+			lnbuf[i] = ch;
+		else
 			break;
-		lnbuf[i] = ch;
 	}
-	if (grep_feof(f) && (i == 0))
+	if (grep_feof(f) && (i == 0) && (ch != '\n'))
 		return (NULL);
 	*len = i;
 	return (lnbuf);
@@ -228,4 +233,8 @@
 		break;
 	}
 	free(f);
+
+	/* Reset read buffer for the file we are closing */
+	binbufptr = NULL;
+
 }

==== //depot/projects/soc2008/gabor_textproc/grep/util.c#77 (text+ko) ====

@@ -114,8 +114,6 @@
 			} else
 				ok = 1;
 			if (ok)
-				/* Reset read buffer before reading other file */
-				binbufptr = NULL;
 				c += procfile(p->fts_path);
 			break;
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812250452.mBP4qOUI055868>