Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in first cell size if file size < BOM length (3 bytes) #111

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ help:

build: simple print_my_column parse_by_chunk pull

test: test-eol
test: test-eol test-tiny

test-tiny: build/simple${EXE}
@[ "`echo '' | $< - 2>&1`" = "" ] && ${TEST_PASS} || ${TEST_FAIL}

test-eol: test-eol-1 test-eol-2 test-eol-3 test-eol-4

Expand Down
9 changes: 6 additions & 3 deletions src/zsv.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,16 @@ enum zsv_status zsv_parse_more(struct zsv_scanner *scanner) {
#endif
size_t bom_len = strlen(ZSV_BOM);
scanner->checked_bom = 1;
if(scanner->read(scanner->buff.buff, 1, bom_len, scanner->in) == bom_len
if((bytes_read = scanner->read(scanner->buff.buff, 1, bom_len, scanner->in)) == bom_len
&& !memcmp(scanner->buff.buff, ZSV_BOM, bom_len)) {
// have bom. disregard what we just read
bytes_read = scanner->read(scanner->buff.buff, 1, capacity, scanner->in);
scanner->had_bom = 1;
} else // no BOM. keep the bytes we just read
bytes_read = bom_len + scanner->read(scanner->buff.buff + bom_len, 1, capacity - bom_len, scanner->in);
} else { // no BOM. keep the bytes we just read
// bytes_read = bom_len + scanner->read(scanner->buff.buff + bom_len, 1, capacity - bom_len, scanner->in);
if(bytes_read == bom_len) // maybe we only read < 3 bytes
bytes_read += scanner->read(scanner->buff.buff + bom_len, 1, capacity - bom_len, scanner->in);
}
} else // already checked bom. read as usual
bytes_read = scanner->read(scanner->buff.buff + scanner->partial_row_length, 1,
capacity, scanner->in);
Expand Down