shithub: mc

Download patch

ref: adff1dabd7ab37d768b7207b57f572e5d27be01a
parent: d51d40bc1674f5845dab709096be84a4e5c51b2b
author: Carlin Bingham <cb@viennan.net>
date: Wed Mar 13 20:50:15 EDT 2019

Fix bio.readto

Don't change rstart on each iteration as that prevents it being able to
return characters at the start of the buffer if the delim is found, and
only read characters from the buffer that were actually checked

--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -427,7 +427,7 @@
 		for i = f.rstart; i <= f.rend - delim.len; i++
 			for j = 0; j < delim.len; j++
 				if f.rbuf[i + j] != delim[j]
-					goto notfound
+					goto nextiter
 				;;
 			;;
 			/* If we found it, return that information */
@@ -438,12 +438,11 @@
 			;;
 			f.rstart += delim.len
 			-> `std.Ok ret
-:notfound
-			f.rstart = i
+:nextiter
 		;;
 		match mode
 		| `Drop:	f.rstart = i
-		| `Read:	readinto(f, &ret, f.rend - f.rstart)
+		| `Read:	readinto(f, &ret, i - f.rstart)
 		| `Keep:
 		;;
 	;;