Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: .zsh_history bugreport



On Fri, 26 Oct 2001, Bart Schaefer wrote:
> This was fixed by the patch in users/4269 and should be working in the
> zsh-4.0.4 release from earlier today.

Hmm.  The start >= l (ell) check can only error-out if the null byte
is at the start of the line (since once a section gets measured, it
can't ever get any shorter).

I think the real fix is to check if the string is too short when we
didn't find a newline at the end (i.e. the buffer should be maxed out
when fgets really didn't read a newline).  What's currently happening
is that we're doubling the readline buffer every time we get a short
read, and we may have only really added a few bytes to the buffer.

I think this is the right fix:

Index: Src/hist.c
--- Src/hist.c	2001/10/15 18:42:52	1.35
+++ Src/hist.c	2001/10/26 18:09:54
@@ -1772,11 +1772,10 @@
     if (fgets(buf + start, *bufsiz - start, in)) {
 	int l = strlen(buf);
 
-	if (start >= l)
-	    return -1;
-
 	if (l) {
 	    if (buf[l - 1] != '\n' && !feof(in)) {
+		if (l < *bufsiz - 1)
+		    return -1;
 		*bufp = zrealloc(buf, 2 * (*bufsiz));
 		*bufsiz = 2 * (*bufsiz);
 		return readhistline(l, bufp, bufsiz, in);

..wayne..



Messages sorted by: Reverse Date, Date, Thread, Author