Skip to content

libcecb: fix four cassette I/O bugs and add regression tests - #84

Merged
tlindner merged 1 commit into
nitros9project:mainfrom
tlindner:fix/libcecb-regressions
Oct 28, 2026
Merged

tlindner merged 1 commit into
nitros9project:mainfrom
tlindner:fix/libcecb-regressions

Conversation

@tlindner

Copy link
Copy Markdown
Member

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.

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.
@tlindner
tlindner merged commit a70967d into nitros9project:main Oct 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant