summaryrefslogtreecommitdiff
path: root/prism/prism.c
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-07-17 15:30:03 -0400
committergit <[email protected]>2024-07-17 19:44:32 +0000
commite77e4aa608a12ea59cefc87abafd72fb2b0c0b9a (patch)
tree96ed90556004047807a8899a8e3c4e146eb2e5e8 /prism/prism.c
parent0fe816f3808cdf647ac549a8ddb2e0540320b890 (diff)
[ruby/prism] Have parse_stream handle NUL bytes
https://github.com/ruby/prism/commit/4a41d298c8
Diffstat (limited to 'prism/prism.c')
-rw-r--r--prism/prism.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 427ac49e3d..2d6cccffba 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -21696,18 +21696,21 @@ pm_parse_stream_read(pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t
#define LINE_SIZE 4096
char line[LINE_SIZE];
- while (fgets(line, LINE_SIZE, stream) != NULL) {
- size_t length = strlen(line);
+ while (memset(line, '\n', LINE_SIZE), fgets(line, LINE_SIZE, stream) != NULL) {
+ size_t length = LINE_SIZE;
+ while (length > 0 && line[length - 1] == '\n') length--;
- if (length == LINE_SIZE && line[length - 1] != '\n') {
+ if (length == LINE_SIZE) {
// If we read a line that is the maximum size and it doesn't end
// with a newline, then we'll just append it to the buffer and
// continue reading.
+ length--;
pm_buffer_append_string(buffer, line, length);
continue;
}
// Append the line to the buffer.
+ length--;
pm_buffer_append_string(buffer, line, length);
// Check if the line matches the __END__ marker. If it does, then stop