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)
This line in
cursor_wordleft
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)