Skip to content

sokol: the clipboard holds the editor's whole code - #3148

Merged
nesbox merged 2 commits into
mainfrom
sokol-clipboard-size
Oct 27, 2026
Merged

nesbox merged 2 commits into
mainfrom
sokol-clipboard-size

Conversation

@nesbox

@nesbox nesbox commented Oct 27, 2026

Copy link
Copy Markdown
Owner

sokol sized its clipboard buffer at 4096 bytes, and its copy keeps buf_size-1 characters: a paste kept only its first 4,095. Code past that lost its tail, while a whole-map copy (65,284 hex characters) and a 64x64 4bpp sprite (4,224) failed the editors' own length checks and pasted nothing.

The buffer now takes TIC_CODE_SIZE + 1, the whole code array plus the terminator. The regular 64K cap and every editor payload fit well inside.

The bigger buffer exposed a PRO-only boundary: MAX_CODE was sizeof(tic_code), the whole array, so the text and its NUL needed one byte more than the array holds — a 512K paste wrote the terminator into cart.binary.data[0] and the state array two bytes past its end. The cap is now sizeof(tic_code) - 1, and the insert paths that checked nothing — tab, line duplication, sexpify, find/replace — stop at the cap too, while paired delimiters count both their bytes. trimWhitespace may now write the terminator on its last allowed byte instead of dropping it.

🤖 Generated with Claude Code

nesbox and others added 2 commits October 27, 2026 13:50
sokol sized its clipboard buffer at 4096 bytes, and its copy keeps
buf_size-1 characters: a paste kept only its first 4,095. Code past
that lost its tail, while a whole-map copy (65,284 hex characters) and
a 64x64 4bpp sprite (4,224) failed the editors' own length checks and
pasted nothing.

The buffer now takes TIC_CODE_SIZE + 1, the whole code array plus the
terminator. The regular 64K cap and every editor payload fit well
inside, and the terminator of a full-size paste needs that extra byte.

Co-Authored-By: Claude Code <noreply@anthropic.com>
MAX_CODE was sizeof(tic_code), the whole array, so the text and its
NUL needed one byte more than the array holds. A pasted, typed or
tabbed edit that brought the code to 512K wrote the terminator into
cart.binary.data[0] and the state array two bytes past its end. The
cap is now sizeof(tic_code) - 1.

The insert paths that checked nothing — tab, line duplication,
sexpify, find/replace — stop at the cap too, and the paired delimiter
inserts count both their bytes. So strlen(code->src) never passes
MAX_CODE, and trimWhitespace may write the terminator on its last
allowed byte instead of dropping it.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@nesbox nesbox self-assigned this Oct 27, 2026
@nesbox
nesbox merged commit 36c16f1 into main Oct 27, 2026
17 checks passed
@nesbox
nesbox deleted the sokol-clipboard-size branch October 27, 2026 13:14
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