Commits

Anonymous committed 6146c98

updated for version 7.3.150
Problem: readline() does not return the last line when the NL is missing.
(Hong Xu)
Solution: When at the end of the file Also check for a previous line.

  • Participants
  • Parent commits 058380f
  • Tags v7-3-150

Comments (0)

Files changed (2)

 	{
 	    if (buf[filtd] == '\n' || readlen <= 0)
 	    {
-		/* Only when in binary mode add an empty list item when the
-		 * last line ends in a '\n'. */
-		if (!binary && readlen == 0 && filtd == 0)
+		/* In binary mode add an empty list item when the last
+		 * non-empty line ends in a '\n'. */
+		if (!binary && readlen == 0 && filtd == 0 && prev == NULL)
 		    break;
 
 		/* Found end-of-line or end-of-file: add a text line to the
 
 	if (tolist == 0)
 	{
-	    /* "buf" is full, need to move text to an allocated buffer */
-	    if (prev == NULL)
-	    {
-		prev = vim_strnsave(buf, buflen);
-		prevlen = buflen;
-	    }
-	    else
-	    {
-		s = alloc((unsigned)(prevlen + buflen));
-		if (s != NULL)
-		{
-		    mch_memmove(s, prev, prevlen);
-		    mch_memmove(s + prevlen, buf, buflen);
-		    vim_free(prev);
-		    prev = s;
-		    prevlen += buflen;
-		}
-	    }
-	    filtd = 0;
+	    if (buflen >= FREAD_SIZE / 2)
+	    {
+		/* "buf" is full, need to move text to an allocated buffer */
+		if (prev == NULL)
+		{
+		    prev = vim_strnsave(buf, buflen);
+		    prevlen = buflen;
+		}
+		else
+		{
+		    s = alloc((unsigned)(prevlen + buflen));
+		    if (s != NULL)
+		    {
+			mch_memmove(s, prev, prevlen);
+			mch_memmove(s + prevlen, buf, buflen);
+			vim_free(prev);
+			prev = s;
+			prevlen += buflen;
+		    }
+		}
+		filtd = 0;
+	    }
 	}
 	else
 	{
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    150,
+/**/
     149,
 /**/
     148,