Fixes the case where multiple lines are read in a single read syscall (it could be better optimized in the future). Also fixes a memory corruption issue when rec == 0.