editor: bound the edit buffer (fix typing/paste overflow and unreloadable max-size saves) - #610
Open
vinej wants to merge 1 commit into
Open
editor: bound the edit buffer (fix typing/paste overflow and unreloadable max-size saves)#610vinej wants to merge 1 commit into
vinej wants to merge 1 commit into
Conversation
The V editor grew its text buffer with no upper bound while typing or pasting: ins-char and paste-line advanced eof past the buffer end ($cbff) into $cc00+ (gfx color RAM, then $d000 I/O registers), silently corrupting memory and crashing forth after a while with larger files. Only file LOADING was size-checked, not editing. Add a `room?` guard so ins-char and paste-line refuse (showing "F" in the status line) instead of overrunning. Also make save and load agree on the maximum size. The load path rejects files over 44 disk blocks, but a buffer filled to $cbff saves as 45 blocks -- so a maxed-out buffer could be saved and then refused on re-open with "too big". Cap bufend to $cba7 (11174 content bytes) so a full buffer always saves within the 44-block reloadable limit. Verified against stock VICE 3.9: eof clamps at the limit with no write past the buffer, and a maximally-filled buffer saves and re-opens.
Collaborator
|
Acknowledged. |
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.
Hi — thanks for durexForth! While using the
veditor I hit two related buffer-size bugs and have a small fix forforth/v.fs. Sharing in case it's useful upstream.1. The edit buffer had no upper bound while editing
ins-charandpaste-linegreweofwith no check against the end of the text buffer. Only loading a file was size-checked, not typing or pasting. Onceeofpassed$cbff, it marched into$cc00+ (hi-res color RAM, then$d000I/O registers), silently corrupting memory — which shows up as forth crashing "after a while," and more readily with larger files.Fix: a small
room?guard soins-char/paste-linerefuse (and showFin the status line) instead of overrunning:: room? ( n -- f ) eof @ + bufend 1+ u< ;2. Save and load disagreed on the maximum size
The load path rejects files over 44 blocks (
here $20 + @ #44 >). But a buffer filled all the way to$cbffsaves as 45 blocks:= $cbff - $a001 = 11262bytes → file= 11264bytes (+2load address) →ceil(11264/254) = 45blocks.So you could fill and save a buffer that the editor then refused to re-open with "too big".
Fix: cap
bufendto$cba7, so a maximally-full buffer stays within the same 44-block reloadable limit:= $cba7 - $a001 = 11174bytes → file= 11176bytes= 44*254→ exactly 44 blocks.$cba7is also still below$cc00, so it satisfies both the physical and the reloadable limit (the smaller one wins).Testing
Verified against stock VICE 3.9:
eofclamps at the limit and nothing is written past the buffer into$cc00.gfx) still load and display correctly.The change is confined to
forth/v.fs(+29/-1, mostly explanatory comments). Happy to adjust naming/comments or split it if you'd prefer.