davidgiven / cpmish

An open source sort-of CP/M 2.2 distribution.
http://cowlark.com/cpmish
Other
351 stars 38 forks source link

cursor_wordleft in qe is wrong #72

Open janko-jj opened 1 month ago

janko-jj commented 1 month ago

This line in cursor_wordleft

uint16_t right = *--gap_start = *--gap_end;

corrupts the edited file. Reason: the invariant of gap_start and gap_end is that the start points to the empty space and gap_end to the first valid character after the gap.

Here, the gap_end is first moved to the "empty space" then that byte is copied over the previously valid character. Each time the function is executed in the line with more words, starting from the last word, more unpredictable bytes are inserted.

(And because it's always a byte, uint8_t should be enough too, but that doesn't change the described behavior)