Skip to content

Commit

Permalink
Prevent accidental discard of line content during file.readLines
Browse files Browse the repository at this point in the history
file.readLines reads chunks of 1024 bytes, looking for newline characters. If we have content at the end of a chunk that isn't a newline, we store that content in a variable called `partialLine`.

However, if an entire chunk goes by without a newline (say, there's a line with >1024 characters), then ideally, we should append the chunk to the stored `partialLine`. However, we were instead *replacing* `partialLine` with the new chunk, accidentally discarding whatever was in `partialLine` before. It's an easy bug to miss, and simply swapping `partialLine =` with `partialLine +=` fixes the issue perfectly.

Fixes #190.
  • Loading branch information
MineRobber9000 committed Dec 4, 2024
1 parent d1f2fcb commit fc2e62b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion MiniScript-cpp/src/ShellIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ static IntrinsicResult intrinsic_readLines(Context *context, IntrinsicResult par
}
}
if (lineStart < bytesRead) {
partialLine = String(&buf[lineStart], bytesRead - lineStart);
partialLine += String(&buf[lineStart], bytesRead - lineStart);
}
}
if (!partialLine.empty()) list.Add(partialLine);
Expand Down

0 comments on commit fc2e62b

Please sign in to comment.