From ebe0b8697bca69abb7e7be1c731da4d54b10e462 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 3 Aug 2024 12:31:51 -0400 Subject: Fix reading chunks from files without trailing newlines --- src/byte_source.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/byte_source.c') diff --git a/src/byte_source.c b/src/byte_source.c index 5443f4dd..122dc0f9 100644 --- a/src/byte_source.c +++ b/src/byte_source.c @@ -19,18 +19,17 @@ serd_byte_source_page(SerdByteSource* const source) const size_t n_read = source->read_func(source->file_buf, 1, source->page_size, source->stream); + source->buf_size = n_read; + if (n_read < source->page_size) { + source->file_buf[n_read] = '\0'; + } + if (n_read == 0) { - source->file_buf[0] = '\0'; - source->eof = true; + source->eof = true; return (source->error_func(source->stream) ? SERD_ERR_UNKNOWN : SERD_FAILURE); } - if (n_read < source->page_size) { - source->file_buf[n_read] = '\0'; - source->buf_size = n_read; - } - return SERD_SUCCESS; } @@ -52,7 +51,7 @@ serd_byte_source_open_source(SerdByteSource* const source, source->stream = stream; source->from_stream = true; source->page_size = page_size; - source->buf_size = page_size; + source->buf_size = 0U; source->cur = cur; source->error_func = error_func; source->read_func = read_func; -- cgit v1.2.1