[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Cvs-cvs] ccvs/src ChangeLog subr.c
From: |
Derek Robert Price |
Subject: |
[Cvs-cvs] ccvs/src ChangeLog subr.c |
Date: |
Wed, 05 Jul 2006 15:27:13 +0000 |
CVSROOT: /cvsroot/cvs
Module name: ccvs
Changes by: Derek Robert Price <dprice> 06/07/05 15:27:13
Modified files:
src : ChangeLog subr.c
Log message:
* subr.c (get_stream): Be slightly more conservative about memory
allocation. Comment more fully.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/ccvs/src/ChangeLog?cvsroot=cvs&r1=1.3465&r2=1.3466
http://cvs.savannah.gnu.org/viewcvs/ccvs/src/subr.c?cvsroot=cvs&r1=1.153&r2=1.154
Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/cvs/ccvs/src/ChangeLog,v
retrieving revision 1.3465
retrieving revision 1.3466
diff -u -b -r1.3465 -r1.3466
--- ChangeLog 3 Jul 2006 16:32:10 -0000 1.3465
+++ ChangeLog 5 Jul 2006 15:27:13 -0000 1.3466
@@ -1,8 +1,13 @@
+2006-07-05 Derek Price <address@hidden>
+
+ * subr.c (get_stream): Be slightly more conservative about memory
+ allocation. Comment more fully.
+
2006-07-03 Mark D. Baushke <address@hidden>
* sanity.sh (recase-5si, recase-7si): Fix cases for MacOS X.
-2006-06-29 Derek Price <address@hidden>
+2006-07-03 Derek Price <address@hidden>
* subr.c (get_file): Factor out...
(get_stream): ...this function. Simplify.
Index: subr.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/src/subr.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -b -r1.153 -r1.154
--- subr.c 3 Jul 2006 11:54:42 -0000 1.153
+++ subr.c 5 Jul 2006 15:27:13 -0000 1.154
@@ -673,11 +673,11 @@
else
{
/* Although it would be cleaner in some ways to just read
- until end of file, reallocating the buffer, this function
- does get called on files in the working directory which can
- be of arbitrary size, so I think we better do all that
- extra allocation. */
-
+ * until end of file, reallocating the buffer, this function
+ * does get called on files in the working directory which can
+ * be of arbitrary size, so it makes some sense to just size
+ * the buffer right the first time.
+ */
if (fstat (fileno (in), &s) < 0)
error (1, errno, "can't stat `%s'", fullname);
@@ -688,17 +688,17 @@
rewind (in);
}
- if (*bufsize < filesize)
- *bufsize = filesize;
+ if (!*buf || *bufsize < filesize + 1)
+ {
+ *buf = xrealloc (*buf, filesize + 1);
+ *bufsize = filesize + 1;
+ }
off = 0;
while (true)
{
size_t got;
- /* Allocates *more* than *BUFSIZE and updates *BUFSIZE. */
- *buf = x2realloc (*buf, bufsize);
-
if (feof (in))
break;
@@ -706,12 +706,20 @@
if (ferror (in))
error (1, errno, "can't read `%s'", fullname);
off += got;
+
+ /* Should only ever test positive reading from stdin. */
+ if (off == *bufsize)
+ /* Allocates *more* than *BUFSIZE and updates *BUFSIZE. */
+ *buf = x2realloc (*buf, bufsize);
}
*len = off;
- /* Force *BUF to be large enough to hold a null terminator. */
+ /* Force *BUF to be large enough to hold a null terminator.
+ * Should only ever test positive reading from stdin.
+ */
if (off == *bufsize)
+ /* Allocates *more* than *BUFSIZE and updates *BUFSIZE. */
*buf = x2realloc (*buf, bufsize);
(*buf)[off] = '\0';
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Cvs-cvs] ccvs/src ChangeLog subr.c,
Derek Robert Price <=