Repository navigation
libcecb: fix four cassette I/O bugs and add regression tests - #84
Merged
Merged
Conversation
Fix four independently reproduced bugs in cassette file handling. Each new regression test was run against the original implementation and confirmed to fail before its corresponding fix. Correct CR detection in _cecb_readln. The buffer pointer was advanced before checking for a carriage return, so the code inspected the next, unwritten byte rather than the byte just read. This could consume subsequent lines, return unexpected EOF, or stop early when the destination buffer already contained CR bytes. Check current[-1] and test two successive CR-terminated lines with zero-filled and CR-filled buffers, followed by EOF. Preserve complete machine-language load and execution addresses in _cecb_create. Both low address bytes were masked with 0x0f, discarding bits 4 through 7. Use 0xff instead. Add a cassette create/close/reopen/stat round-trip test for load address 0x1234 and execution address 0xabcd; the original code returned load address 0x1204. Discard buffered block data when rewinding with _cecb_seek. Resetting the tape position without clearing current_pointer and length allowed stale bytes from a partially consumed block to precede the file contents after rewind. Clear both fields and test complete rereads after partial reads and after EOF for CAS, C10, 8-bit WAV, and 16-bit WAV. The original partial-read case returned 22 bytes for a 13-byte file. Reject _cecb_write calls on paths without FAM_WRITE. Previously, writing to a read-only path returned success and modified its buffered read state. Return EOS_BMODE before touching the buffer, matching the other write APIs. Test rejection after a partial read and verify that the position and remaining file contents are preserved. Validation: make -C build/unix completed successfully, including all 36 tests across six suites (8 libcecb tests). git diff --check passed. AGENTS.md is excluded from this commit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix four independently reproduced bugs in cassette file handling. Each new regression test was run against the original implementation and confirmed to fail before its corresponding fix.
Correct CR detection in _cecb_readln. The buffer pointer was advanced before checking for a carriage return, so the code inspected the next, unwritten byte rather than the byte just read. This could consume subsequent lines, return unexpected EOF, or stop early when the destination buffer already contained CR bytes. Check current[-1] and test two successive CR-terminated lines with zero-filled and CR-filled buffers, followed by EOF.
Preserve complete machine-language load and execution addresses in _cecb_create. Both low address bytes were masked with 0x0f, discarding bits 4 through 7. Use 0xff instead. Add a cassette create/close/reopen/stat round-trip test for load address 0x1234 and execution address 0xabcd; the original code returned load address 0x1204.
Discard buffered block data when rewinding with _cecb_seek. Resetting the tape position without clearing current_pointer and length allowed stale bytes from a partially consumed block to precede the file contents after rewind. Clear both fields and test complete rereads after partial reads and after EOF for CAS, C10, 8-bit WAV, and 16-bit WAV. The original partial-read case returned 22 bytes for a 13-byte file.
Reject _cecb_write calls on paths without FAM_WRITE. Previously, writing to a read-only path returned success and modified its buffered read state. Return EOS_BMODE before touching the buffer, matching the other write APIs. Test rejection after a partial read and verify that the position and remaining file contents are preserved.
Validation: make -C build/unix completed successfully, including all 36 tests across six suites (8 libcecb tests). git diff --check passed. AGENTS.md is excluded from this commit.